Skip to content

Instantly share code, notes, and snippets.

@zealot128
Last active December 27, 2015 21:49
Show Gist options
  • Select an option

  • Save zealot128/8940e1a91c22d31f1c0d to your computer and use it in GitHub Desktop.

Select an option

Save zealot128/8940e1a91c22d31f1c0d to your computer and use it in GitHub Desktop.
watermark imagemagick - add transparent png to all images in a folder as percentage width of the original

Image magick Watermark example

Create a watermark image, should be transparent background. watermark.png

Run script in the folder where all jpgs are located:

cd someproductimages
bash ../watermark.sh
...
# make sure there are no spaces in filenames
rename 's/ +/_/g' *.jpg
# path to watermark image
watermark="../watermark.png"
# create extra folder in current folder
mkdir -p watermark
for i in `ls *jpg`
do
# calculate width of watermark: e.g. 1/3 of width
echo "processing $i"
full_width=`identify -format '%w' ""$i""`
width=`expr $full_width / 3`
echo "Watermark size: $width / $full_width"
composite -geometry x$width+15+15 -dissolve 50% -gravity SouthWest $watermark "$i" "watermark/$i"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment