O'Reilly logo

Wicked Cool Ruby Scripts by Steve Pugh

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required