RMagick – A Magic Way of Playing with Images

Posted: August 7, 2008 in Ruby on Rails, Web Development
Tags: , , ,

I spent a good amount of time in digging about another ruby gem.
RMagick is the magic gem I am talking about.In ruby, magic means
something amazing, something wow.You don’t have to scratch your
head to know about much of the background details. Just know how
to use it, and it’s all done!

RMagick is a binding from Ruby to the ImageMagick library. You can
use it to resize images, create thumbnails of images in a directory,
crop images, create watermarks for images and much more.

+ “rmagick” is the gems you need to include.

+ Magick::Image.read is a method returns an array if you will try to open gif
animation with multiple frames. In our case, we will get a single frame as it’s
a png image. And “.first” gives us the 1st frame which is the image itself.

+ change_gemometry method takes a new size as an argument and passes
the value to the associated blocks.

+ resize! method resizes the image and write saves the files with a new name.

You may like to try out other features of RMagick. Like conversation of image
formats. (PNG to JPG or others!)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s