views:

102

answers:

2

I want to know how to open and manipulate a simple image file in Ruby language.

I don't need to do any advanced stuff, just things like open(), get_pixel() and put_pixel() and I don't wanna use any gem for doing that, but just to know the barehands-ruby way.

+1  A: 

If by "simple image file" you refer to JPEG, GIF or so, it's tough luck because you'd have to implement all the decoding logic, which is far from being simple (take a look here for more info, but briefly because you really don't want to go into details ;)).

After decoding, eventually what you get is a matrix (two-dimensional array) of pixel information (usually three numbers for red, green and blue component, but other options exist). Then your methods get_pixel and set_pixel are trivial.

What Ruby folks usually do in such cases is wrap already existing C library for image manipulation, into a library such as rmagick.

Mladen Jablanović
Yeah, I've reading a lot about it and you are completely right. Image manipulation is not as simple as python and php make you believe. =(Anyway, I don't understand why ruby doesn't have built-in functions for such tasks. And about RMagick, I could install it on ubuntu but no success trying on centos.Anyway, thank you very much, Mladen.
Erik Escobedo
If by "built-in function" you refer to standard Ruby library, I don't see why image manipulation should be part of it. It's pretty domain specific and well covered by 3rd party libraries (gems), and not a bit harder to use than in PHP or Python. Regarding the rmagick installation, I think you need to have ImageMagick installed first.
Mladen Jablanović
A: 

Paperclip + ImageMagick did the trick. It's awesome and easy

Erik Escobedo