#!/usr/bin/env ruby # Script to Rotate an Image # Usage: rotateimage.rb ANGLE IMAGE (OUTPUT IMAGE) # ANGLE can be CW, CCW, or 180 # IMAGE can be any file ImageMagick can parse # OUTPUT IMAGE is optional - omitted it changes in place. require 'RMagick' include Magick def usage() puts "Usage: rotateimage.rb ANGLE IMAGE (OUTPUT IMAGE) ANGLE can be CW, CCW, or 180 IMAGE can be any file ImageMagick can parse OUTPUT IMAGE is optional - omitted it changes in place." end inputangle = ARGV[0] if (inputangle == "CW") angle = 90 elsif (inputangle == "CCW") angle = -90 elsif (inputangle == "180") angle = 180 else usage() exit end image = ARGV[1] if (!image) usage() exit end imagelist = ImageList.new(image) newimage = imagelist.rotate(angle) output = ARGV[2] if (output) puts "Output Image: "+output newimage.write(output) else puts "Output Image: "+image newimage.write(image) end