I've written two versions of this script. The first one I'll show overwrites all of the images in a directory with the watermarked images. This should be done with some degree of caution as there is no way to undo the changes unless you have the files backed up. Save the following script in your ~/bin/ directory and name it wm-ow.

The second version of this script will not overwrite your images. It will create a new file with _wm inserted into the file name. This is the version you should use if you're not sure about what settings to use in the script. Save the following in ~/bin/ as wm-new.

16 Comments

does'nt work for me. regardless of which path I use for the watermark graphic, I get an error when running the script that it cant open my watermark.png , no file or directory. i have my file in home/myname/Pictures/watermark.png and this is the path I have entered in the script.

basename requires you to provide the extension you want to strip, so you can't make it generic for all image types. Perhaps a loop could be written to figure out the correct extension, but it seems like it would be more work than my current code.

On the other hand, my script assumes that the only '.' in the file name is between the name and the extension, so it's not perfect either.

Surfrock66 - did you perhaps have several terminals open to different directories and delete the working directory of one of the other terminals? You might get this message if you try to run the script from a directory that no longer exists. A google search on the error suggests some possible causes.

chomp gets rid of the "new line" character that is included when you hit the "Enter/Return" button after submitting data. In this case, the year. The "convert" command is a ImageMagick command (man imagemagick for details).

@ Duane - Nice script. It looks like it could be done a little more efficiently. I like the ls | grep -ic jpg part. That's a neat trick to count the files. I like your watermark image too. I'll have to try making one like that in GIMP.

The composite command should work fine if you just overwrite the file:composite -gravity SouthEast $watermark "$i" "$i"
Then you can skip the rm command to clean up.