linux-batch-watermark-images-ubuntu

linux-batch-watermark-images-ubuntuPreviously I  had a music website in which I publish photos from recent Tamil movies,But I had a problem with piracy issues,many people copied photos from my website and published to their website so i decided to add a watermark to every image,But the only restriction is Since I don’t use Windows, I could not find any batch watermark software’s for Linux but after lot of research i found a perfect and fastest way to add image watermark to photos.

1.Install the ImageMagick library (http://www.imagemagick.org) In fedora you can install using Yum
yum install ImageMagick

In other linux distributions you can Install from source, I hope this will be useful to Ubuntu users.
2. Using text editor make a shell script file (.sh) ( yourfilename.sh)
#!/bin/bash
###########################################
# REQUIRES:    ImageMagick, coreutils
# VERSION:    1.0
# DESCRIPTION:    A script to add a watermark and overwrite all images in a directory.
#
# This script will watermark all of the images in a directory. Warning! This will overwrite the files.
#   gravity         NorthWest, North, NorthEast, West, Center,
#                   East, SouthWest, South, or SouthEast

###########################################
# Initialize variables
WM=$HOME/Documents/Watermark.png  # This is the path to your watermark image
SCALE=50                          # This sets the scale {71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} of your watermark image

# Warning
echo -e "This will overwrite all of the images in this directory."\\n"Are you sure want to continue? {Y/n}"
read REPLY

if
	[ "$REPLY" != "n" ] && [ "$REPLY" != "N" ]
then
	file -i * | grep image | awk -F':' '{ print $1 }' | while read IMAGE
		do
			echo Watermarking $IMAGE
			composite -dissolve 40{71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} -gravity center -quality 100 \( $WM -resize $SCALE{71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} \) "$IMAGE" "$IMAGE"
		done
else
	echo exiting
	exit 0
fi

exit 0
Note : This is an script by Linerd (http://tuxtweaks.com) you can view the original script here
3. Now in line 13 of the above script enter the path of your watermark image file such as your website logo.For example

/home/vividvilla/Documents/logo.png

where logo.png is the image which we are going o add in original images
,you can change the position of the logo at line 26
currently the logo will be watermarked in center you change this to Top Left by changing line 26

composite -dissolve 40{71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} -gravity center -quality 100 \( $WM -resize $SCALE{71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} \) "$IMAGE" "$IMAGE"

to

composite -dissolve 40{71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} -gravity NorthEast -quality 100 \( $WM -resize $SCALE{71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} \) "$IMAGE" "$IMAGE"

In above script i have commented about how to the postion to change the watermark position.
4. Now copy the shell script file to /bin folder
5. Inorder to execute the script change the permission of the file using this command

chmod +x /bin/yourfilename.sh

where yourfilename.sh is your shell script name
6. Now place all you file to be watermarked in any directory and make that directory as your current directory
7. Execute the shell script file
for example take look at these screenshots
In above screenshot you can see that watermark.sh is the shell script file.
8. Examples
Without Watermark
With Watermark

 

You can see two watermarks since I just repeated some steps and changes the Logo position

 

#!/bin/bash

###########################################
# DESCRIPTION:	A script to add a watermark and overwrite all images in a directory.
#
# This script will watermark all of the images in a directory. Warning! This will overwrite the files.
#   gravity         NorthWest, North, NorthEast, West, Center,
#                   East, SouthWest, South, or SouthEast

###########################################

# Initialize variables
WM=/home/vividvilla/Documents/logo/mp3tamil.png  # This is the path to your watermark image
WM1=/home/vividvilla/Documents/logo/watermark.png
SCALE=100                          # This sets the scale {71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} of your watermark image

# Warning
echo -e "This will overwrite all of the images in this directory."\\n"Are you sure want to continue? {Y/n}"
read REPLY

if
	[ "$REPLY" != "n" ] && [ "$REPLY" != "N" ]
then
	file -i * | grep image | awk -F':' '{ print $1 }' | while read IMAGE
		do
			echo Watermarking $IMAGE
			composite -dissolve 40{71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} -gravity SouthEast -quality 100 \( $WM -resize $SCALE{71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} \) "$IMAGE" "$IMAGE"
		done
	file -i * | grep image | awk -F':' '{ print $1 }' | while read IMAGE
		do
			echo Watermarking $IMAGE
			composite -dissolve 40{71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} -gravity NorthWest -quality 100 \( $WM1 -resize $SCALE{71b550cbed0aca3fea2335d26076176dc834a5ad6e765af844b2cea64fe7483b} \) "$IMAGE" "$IMAGE"
		done
else
	echo exiting
	exit 0
fi

exit 0

 

Warning : This script overwrites the current file.

Thats it now you can any number of watermarks to your Images In very simple and Fastest way.Please Leave a comment if you face any problem

 

Similar Posts