Ruby is a fantastic programming language, it provides a lot of features.
It can use the imagemagick to handle and filter pictures.
In this short script I'm going to resize a png image and then I'm going to save it with a new name.
Since I need to resize an image, my script will require Ruby Magick and ruby gems (take a look to My minimal installation of Ruby on Ubuntu 12.04 to install the needed libraries).
And, here you are the program:
require 'rubygems'
require 'RMagick'
image = Magick::Image.read("gg.png").first
image.change_geometry!("100×100"){ |cols, rows, img|
new_image = img.resize(cols, rows)
new_image.write("resized.png")
}
It's really simple, the first two lines set the libraries.
Then, I ask to open the file named gg.png (I'm not checking if it exists, but if you want to do a full working program you have to)
With lines #2, #3 and #4 I'm changing the geometry, creating the new image and last I'm saving back with the new name ("resized.png")