Creating a shadow with RMagick

Posted by mick on June 26th, 2009 filed in Ruby

RMagick is a ruby library for performing image manipulation. Whenever I use it I’m amazed at what can be achieved with just a few lines of code, so I thought I’d share my latest experience.

The context was that I was working on the website for 2WayFitness and I wanted to have screenshots that had a shadow effect behind them. For example, I wanted to turn the following:


into this:


Turned out, that to do that all I needed was the following code:

require 'rmagick'
include Magick

image ="image.png").first

shadow = image.shadow(0,0,3.0)
shadow = shadow.colorize(1, 1, 1, "gray45")
image = shadow.composite(image, 0, 12, Magick::OverCompositeOp)


I think that’s pretty cool! Kudos to the RMagick guys and to the people who developed the ImageMagick and GraphicsMagick image processing libraries upon which RMagick is built.

Leave a Comment