16 Comments

  1. Martin

    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.

    Reply

    • Did you try it with a leading / on the path?
      /home/myname/Pictures/watermark.png

      Or try
      ~/Pictures/watermark.png

      Reply

  2. Damian

    Nice article! May be you shuld use basename instead of pipe and cut but I'll give a try.

    Thanks.

    Reply
    • Linerd

      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.

      Reply

  3. I'm having some issues; i'm completely new to Bash scripts. I'm getting an error:

    shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory

    Any thoughts?

    Reply
    • Linerd

      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.

      I don't think the error has anything to do with the program itself.

      Reply

  4. Hi,

    I found a Webapplication that does batch watermarking (upto 20 images) and it has lot of options to customize the watermark.

    http://watermark-images.com

    Prasad.

    Reply

  5. "@ Kim – Interesting. I haven’t gotten into perl yet, so I don’t quite follow everything that’s going on. I’m guessing that chomp is a perl specific command?"

    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).

    Reply
  6. Jose_X

    I would change the first script to run only after Y/y. This way if the person types "stop" or "help" or "no" or "" etc, they won't have to worry.

    BTW, you can avoid being there to type "y" by doing: yes | thescript

    Reply

  7. Nice work!

    I wrote a similar script that copies

    http://duane-pwns.blogspot.com/2008/09/batch-watermarking-photos-in-bash.html

    Yours is more concise, but mine was written for the specific purpose of creating a directory of smaller, watermarked images within the current directory. Let me know what you think!

    Reply
    • Linerd

      @ 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.

      @ Kim - Interesting. I haven't gotten into perl yet, so I don't quite follow everything that's going on. I'm guessing that chomp is a perl specific command?

      @ both - I guess what sets my script apart is the handling of multiple image file types. There's a lot going on in file -i * | grep image | awk -F':' '{ print $1 }' | while read IMAGE.
      file -i * - lists the files and shows file MIME type.
      grep image - filters the list for image files
      awk -F':' '{ print $1 }' - cuts the file name from the list item (everything before the ":" )
      while read IMAGE - takes the file name output from awk and stores it in $IMAGE

      I tested on a directory with .gif, .jpg, .png, .tiff files. File names with spaces work.

      Reply

  8. Here are mine. Resized, thumbnailed, and watermarked at the same time:

    http://kimbriggs.com/computers/computer-software/perl-image-manipulation.file

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>