run `ruby watermark.rb source_file.png output_file.png "My watermark text"
Created
February 28, 2021 13:46
-
-
Save unkmas/0a5c2923d4e944bcc3c7932fe3b7a69a to your computer and use it in GitHub Desktop.
Quick watermark for photos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require "vips" | |
im = Vips::Image.new_from_file ARGV[0], access: :sequential | |
# make the text mask | |
text = Vips::Image.text ARGV[2], width: 5000, dpi: 150, font: "sans bold 48" | |
text = text.rotate(-45) | |
# make the text transparent | |
text = (text * 0.3).cast(:uchar) | |
text = text.gravity :centre, 1500, 1500 | |
text = text.replicate 1 + im.width / text.width, 1 + im.height / text.height | |
text = text.crop 0, 0, im.width, im.height | |
# we make a constant colour image and attach the text mask as the alpha | |
overlay = (text.new_from_image [242, 185, 195]).copy interpretation: :srgb | |
overlay = overlay.bandjoin text | |
# overlay the text | |
im = im.composite overlay, :over | |
im.write_to_file ARGV[1] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment