Add your signature to an image with ImageMagick and Ruby

25 Feb 2011

require "RMagick"

ARGV.each do |file|

    image = Magick::Image.read(file).first

    image = image.resize_to_fit(996, 996)

    if image.orientation == Magick::LeftBottomOrientation then
        image.orientation = Magick::TopLeftOrientation
        image = image.rotate(-90)
    end

    signature = Magick::Draw.new
    signature.annotate(image, 0, 0, 10, 10, '© Mickael BLATIERE') do
        self.gravity = Magick::SouthEastGravity
        self.pointsize = 20
        self.font_family = 'Trebuchet MS'
        self.fill = '#ffffff'
    end

    image.border!(2, 2, '#ffffff')
    image.border!(12, 12, '#000000')

    out = file.gsub(/\./, '-wmr.')
    image.write(out)

end