RMagick Portfolio - Transformations
Original Image

Here's a few examples of what RMagick can do. Each of the images on these pages was created using RMagick. To the right of each image is the Ruby program that created it.

This page demonstrates some basic transformations. The next two pages show special effects and the drawing API.

Cropped Image Crop to a new size
require 'RMagick'

clown = Magick::ImageList.new("clown.jpg")
face = clown.crop(50, 15, 150, 165)
white_bg = Magick::Image.new(clown.columns, clown.rows)
clown = white_bg.composite(face, 50, 15,
                               Magick::OverCompositeOp)
clown.write('crop.jpg')
Thumbnail Create Flickr-style thumbnails
require 'RMagick'

clown = Magick::Image.read("clown.jpg").first
clown.crop_resized!(75, 75, Magick::NorthGravity)
clown.write('crop_resized.jpg')
Rotated Image Rotate to any angle
require 'RMagick'

clown = Magick::ImageList.new("clown.jpg")
clown = clown.rotate(90)
clown.write('rotate.jpg')
Flipped Image Flip it!
require 'RMagick'

clown = Magick::ImageList.new("clown.jpg")
clown.flip!
clown.write('flip.jpg')
Annotated Image Add text
require 'RMagick'

clown = Magick::ImageList.new("clown.jpg")
text = Magick::Draw.new
text.annotate(clown, 0, 0, 0, 60, "My friend!") {
    self.gravity = Magick::SouthGravity
    self.pointsize = 48
    self.stroke = 'transparent'
    self.fill = '#0000A9'
    self.font_weight = Magick::BoldWeight
    }
clown.write('annotate.jpg')
Monochrome Image Make it black-and-white
require 'RMagick'

clown = Magick::ImageList.new("clown.jpg")
clown = clown.quantize(256, Magick::GRAYColorspace)
clown.write('monochrome.jpg')
Watermark Image Add a watermark
require 'RMagick'

mark = Magick::Image.new(300, 50) do
    self.background_color = 'none'
    end
gc = Magick::Draw.new
gc.annotate(mark, 0, 0, 0, 0, "Image by RMagick") do
    self.gravity = Magick::CenterGravity
    self.pointsize = 32
    self.font_family = "Times"
    self.fill = "white"
    self.stroke = "none"
    end
mark.rotate!(-90)

clown = Magick::Image.read("clown.jpg").first
clown = clown.watermark(mark, 0.15, 0, Magick::EastGravity)
clown.write("watermark.jpg")

Raised Image Add raised edges
require 'RMagick'

clown = Magick::ImageList.new("clown.jpg")
clown = clown.raise
clown.write('raise.jpg')
<- RMagick Home Page | Special Effects ->