A few days ago I wanted to watermark few of my images on cmd line and I wrote this blog http://bullet-bala.blogspot.in/2012/06/adding-watermark.html and the trouble which I had was that the Watermark was either very small or very big and got out of the final image. The result of which I created a small python script to extract the Dimension of an image and resize my Watermarker so my water marker always looks okay on the final image.
Initial step create an watermark image and put in inside /usr/local/src/watermark1.jpeg
Next call my python script on command line like so
$cat watermark.py
#!/usr/bin/python
#Author: Balasubramaniam Natarajan
#Create WaterMark
import subprocess
import sys
import os
#Here I want to get the File to WaterMark
if len(sys.argv) < 2:
print"You need to specify the src image file"
print"For example"
print"watermark.py"
sys.exit()
src = sys.argv[1]
print "Your Input Image File is: ", src
#This command extracts the Dimentions of my Image
CreateImgSize = "identify -format '%wx%h\n' "+src
Size = subprocess.Popen(CreateImgSize, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, error = Size.communicate()
#This is to trim the additional new line from the above command.
out = out.rstrip('\n')
print "The Dimension of the Image is: ",out, " Pixels"
#This is going to be the name of the output file.
WaterMarkedImage = src+"_output.png"
WaterMarkCmd = "composite -dissolve 10% -gravity south -resize ", out, " /usr/local/src/watermark1.jpeg ",src, WaterMarkedImage
# The above WaterMarkCmd become tuple which os.system can't accept.
#print type(WaterMarkCmd)
# FinalCmd is a string got from the tuple
FinalCmd = " ".join(WaterMarkCmd)
print "The final command is: ", FinalCmd
os.system(FinalCmd)
#END
Initial step create an watermark image and put in inside /usr/local/src/watermark1.jpeg
Next call my python script on command line like so
$cat watermark.py
#!/usr/bin/python
#Author: Balasubramaniam Natarajan
#Create WaterMark
import subprocess
import sys
import os
#Here I want to get the File to WaterMark
if len(sys.argv) < 2:
print"You need to specify the src image file"
print"For example"
print"watermark.py
sys.exit()
src = sys.argv[1]
print "Your Input Image File is: ", src
#This command extracts the Dimentions of my Image
CreateImgSize = "identify -format '%wx%h\n' "+src
Size = subprocess.Popen(CreateImgSize, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
out, error = Size.communicate()
#This is to trim the additional new line from the above command.
out = out.rstrip('\n')
print "The Dimension of the Image is: ",out, " Pixels"
#This is going to be the name of the output file.
WaterMarkedImage = src+"_output.png"
WaterMarkCmd = "composite -dissolve 10% -gravity south -resize ", out, " /usr/local/src/watermark1.jpeg ",src, WaterMarkedImage
# The above WaterMarkCmd become tuple which os.system can't accept.
#print type(WaterMarkCmd)
# FinalCmd is a string got from the tuple
FinalCmd = " ".join(WaterMarkCmd)
print "The final command is: ", FinalCmd
os.system(FinalCmd)
#END
This comment has been removed by a blog administrator.
ReplyDeletePhoto Watermark does exactly what the name suggests – it lets you add watermarks to photos – but the types of watermarks you can add are quite varied.
ReplyDeleteNot only can you add custom text as a watermark (including changing the font, size and color), you can also use your signature (or any other hand-written text) as a watermark by writing on the screen.
You can also apply stickers, a timestamp, a location, a mosaic effect, or ‘graffiti’ (which basically just lets you go wild on your images with a digital paintbrush). Whether you want to protect your photo or just log when and where it was taken, there should be a tool here to suit.
Photo Watermark is free, but it’s quite heavy on adverts. For $0.99/£0.89 per month you can get rid of them, but unless you’re adding watermarks to a ton of images it’s probably not worth it.
Photo Watermark does exactly what the name suggests – it lets you add watermarks to photos – but the types of watermarks you can add are quite varied.
ReplyDeleteNot only can you add custom text as a watermark (including changing the font, size and color), you can also use your signature (or any other hand-written text) as a watermark by writing on the screen.
You can also apply stickers, a timestamp, a location, a mosaic effect, or ‘graffiti’ (which basically just lets you go wild on your images with a digital paintbrush). Whether you want to protect your photo or just log when and where it was taken, there should be a tool here to suit.
Photo Watermark is free, but it’s quite heavy on adverts. For $0.99/£0.89 per month you can get rid of them, but unless you’re adding watermarks to a ton of images it’s probably not worth it.
Photo Watermark does exactly what the name suggests – it lets you add watermarks to photos – but the types of watermarks you can add are quite varied.
ReplyDeleteNot only can you add custom text as a watermark (including changing the font, size and color), you can also use your signature (or any other hand-written text) as a watermark by writing on the screen.
You can also apply stickers, a timestamp, a location, a mosaic effect, or ‘graffiti’ (which basically just lets you go wild on your images with a digital paintbrush). Whether you want to protect your photo or just log when and where it was taken, there should be a tool here to suit.
Photo Watermark is free, but it’s quite heavy on adverts. For $0.99/£0.89 per month you can get rid of them, but unless you’re adding watermarks to a ton of images it’s probably not worth it.