To add watermarks on image using Ruby we need RMagick
For that we need to install rmagick and require it
To require 'rmagick' we need to require 'rubygems'
For example we have myimage.jpg file in our directory
require 'rubygems'
require 'RMagick'
image = Magick::Image.read("myimage.jpg").first
mark = Magick::Image.new(image.columns, image.rows)
water_mark = Magick::Draw.new
water_mark.gravity = Magick::NorthWestGravity
water_mark.pointsize = 24
water_mark.font_family = "White"
water_mark.font_weight = Magick::BoldWeight
water_mark.stroke = 'none'
water_mark.annotate(mark, 0, 0, 0, 0, "Watermark by Sriram")
mark = mark.shade(true, 310, 30)
image.composite!(mark, Magick::NorthGravity, Magick::HardLightCompositeOp)
puts " enter the file name to save"
file_name = gets
wm = "#{file_name}.jpg".sub(/\./, "-wm.")
puts "The file is saved by the name #{wm}"
image.write(wm)
go to folder path and run
ruby watermark.rb
here my example rubycode with the file name watermark.rb and myimage.jpg are in same folder so i doesn't need to give the full path of the image
just i mentioned the name of the image
Thanks
Sriram





