Loading an image from a subdirectory in a gem - ruby

I used bundler to create a new gem, and I'm playing with rubygame. So far, it's going OK, except I can't get images on the Surface because I can't figure out what the path is to my images directory. I know it's sad, but I'm sorta used to Rails loading my images for me.
The full path to the image is: /usr/local/src/jewel_thief/lib/jewel_thief/images/player.png.
and I'm trying to use it in:
/usr/local/src/jewel_thief/lib/jewel_thief/player.rb (view source)
What am I doing wrong?

Change
#image = Surface.load 'jewel_thief/images/player.png'
To
#image = Surface.load '/jewel_thief/images/player.png'
I think following also work
#image = Surface.load '/jewel_thief/lib/jewel_thief/images/player.png'

The path ended up being this:
#image = Surface.load 'lib/jewel_thief/images/player.png'
Finally, after being stumped for hours. Thanks for the help though! Really.

Related

Display image with ruby processing

So this seems simple from all the samples I saw on github and elsewhere but sadly I can't get a simple image to display with ruby processing. Any help would be much appreciated.
My code:
attr_reader :img
def setup
size(600, 600)
#img = loadImage("chess.jpg")
end
def draw
image(#img, 10, 10)
end
The code is in ~/RP-image/scratchpad.rb The jpg is in ~/RP-image/data/chess.jpg
I've tried every permutation of load_image loadimage loadImage etc I get the response in terminal of:
The file "chess.jpg" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.
Java::JavaLang::NullPointerException
processing.core.PGraphics.image(processing/core/PGraphics.java:3572)
processing.core.PApplet.image(processing/core/PApplet.java:12773)
java.lang.reflect.Method.invoke(java/lang/reflect/Method.java:483)
RUBY.draw(image-scratchpad.rb:8)
processing.core.PApplet.handleDraw(processing/core/PApplet.java:2386)
processing.core.PGraphicsJava2D.requestDraw(processing/core/PGraphicsJava2D.java:240)
processing.core.PApplet.run(processing/core/PApplet.java:2256)
java.lang.Thread.run(java/lang/Thread.java:745)
As far as I know you dont need to "add an image to the sketch" other than load it with the loadimage command.

pygame, where does it save an image?

I am making a game and need to save a image of the screen, so i googled it and found this methode:
pygame.image.save(window, "screenshot.jpeg")
the problem is though, I don't know where it saves it, because it doesnt appear in the same folder as the programm is in for me.
Try using an absolute filepath, like "C:\screenshot.jpeg"

RMagick posterize and other does not work

I guy's
i have write this code:
require 'RMagick'
include Magick
img = Image.read("small_img.gif").first
img.posterize
img.display
exit
the result of image don't change
i've tested blur_image, oil_paint, other but don't work
only rotate! work form me, maybe have writed too bad the code?
p.s. sorry for my bad english
This line
img.posterize
returns a new image object, it does not alter the image in place. So if you do the following
new_img = img.posterize
new_img.display
you should see results of your test.
The same applies to a lot of rmagic transformations.

image() modifies actual image content in MATLAB

I am displaying an image in figure window in MATLAB using following code.
im = imread('Image02.tif');
processAndDisplayImage(im);
hImage = image(im);
set(hImage,'ButtonDownFcn',#clickInImage);
But problem is that the third line above makes the image changed for some reason I don't know. Is there any way to get image handle without the modification?
UPDATE: Resolved the problem. Please refer to my answer below.
The image graphical command cannot change the image. I can only guess that it shows the image in a way you don't want it. Inspect the range of the image -
max(im(:));
and also the type:
class(im);
and try to figure out what is wrong
Perhaps you could modify processAndDisplayImage so that it returns a handle to the displayed image as an output variable?
Instead of
hImage = image(im);
I used following to solve my problem.
[hImage hfig ha] = imhandles(gcf);
But I still don't understand image command does to the actual image displayed on figure.

Set relative image size Paperclip [Rails]

Is it posible to set a relative size to a image with paperclip?
Does exists something like this?
:medium => "50x50%"
see following links I think it would help you
watch resize option
https://github.com/thoughtbot/paperclip/wiki/Thumbnail-Generation
and following link examples are there
http://www.imagemagick.org/Usage/resize
http://www.imagemagick.org/Usage/resize/#percent
Thanks.

Resources