Can someone please spend me some line of codes, that add a text at the bottom of an image? I want to use Rmagick but I'm open for other tools also.
I found this also and it works for me perfect.
require 'RMagick'
include Magick
#Dimisions based on an image 3072x2048
unless ARGV[0] and File.exists?(ARGV[0])
puts "\n\n\nYou need to specify a filename: watermark.rb <filename>\n\n\n"
exit
end
img = Image.read(ARGV[0]).first
new_img = "wm_#{ARGV[0]}"
if File.exists?(new_img)
puts "Image already exists. Unable to create file."
exit
end
watermark = Image.new(600, 50)
watermark_text = Draw.new
watermark_text.annotate(watermark, 0,0,0,0, "foo bar bla") do
watermark_text.gravity = CenterGravity
self.pointsize = 50
self.font_family = "Arial"
self.font_weight = BoldWeight
self.stroke = "none"
end
watermark.rotate!(45)
watermark = watermark.shade(true, 310, 30)
img.composite!(watermark, SouthWestGravity, HardLightCompositeOp) #Bottom-Left Marking
watermark.rotate!(-90)
img.composite!(watermark, NorthWestGravity, HardLightCompositeOp) #Top-Left Marking
watermark.rotate!(90)
img.composite!(watermark, NorthEastGravity, HardLightCompositeOp) #Top-Right Marking
watermark.rotate!(-90)
img.composite!(watermark, SouthEastGravity, HardLightCompositeOp) #Bottom-Right Marking
puts "Writing #{new_img}"
img.write new_img
Have look at the RMagick docs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With