Resize a Picture

Resize a Picture

resizePhoto.rb

Digital SLR cameras provide tremendous resolution, but that makes for very large files. Many times I have found myself wanting to use a picture in a website or email and am forced to fire up the GIMP to shrink the pictures to a more manageable size. This script will tear through shrinking a picture to whatever size you want. We already covered how to rip through files to generate thumbnails in a previous script (see "#24 Creating a Thumbnail" on Creating a Thumbnail). This script is similar, but instead of shrinking everything to 10 percent, we'll set the final dimensions in the code—a nice feature if you're embedding images into the frame of a website.

The Code

 require 'RMagick'
 include Magick

 unless ...

Get Wicked Cool Ruby Scripts now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.