views:

69

answers:

1

I'm looking for a way to load up an existing png image, and do a pixel by pixel manipulation of the values. Ideally, something like

image = Image.open('my.png')
image = image.map_each_rgb do |r, g, b|
  [r-12, g+2, b+30]
end
image.save('my.png')

I've looked into rmagick, but couldn't find a way to achieve this.

Are there any alternatives that would allow such image editing?

+2  A: 

How about RMagick's each_pixel method?

http://studio.imagemagick.org/RMagick/doc/image2.html#each_pixel

img.each_pixel {|pixel, c, r| block }
jrdioko
Someone told me, that RMagick has memory leaks.
Nakilon
jrdioko