batch watermarking entire directory

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
blondzie
Posts: 4
Joined: 2014-12-29T12:37:13-07:00
Authentication code: 6789

batch watermarking entire directory

Post by blondzie »

I created a script awhile ago and now it seems to no longer work.

I want to take a directory of large images, resize them to a width of 1400 pixels, since height and oreintation will vary. Then add "watermark.png" over the bottom of the image. The PNG "watermark.png" is going to be 1400 pixels wide and will be in the same directory as the images and watermark.

then I had the results go into a "watermarked" folder within the same directory
here is what I used to have working for me. now it no longer works, Please help.

@echo off
IF NOT EXIST watermarked mkdir watermarked
FOR %a in ("*.jpg") DO (convert "%a" -resize 1400x5000 -gravity south -geometry +0+0 null: "watermark.png" -layers composite "watermarked\%~nxa")
PAUSE
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: batch watermarking entire directory

Post by fmw42 »

If you are using the same wartermark.png on all the images in the directory, why not just use mogrify with alpha composition. See http://www.imagemagick.org/Usage/basics ... fy_compose
blondzie
Posts: 4
Joined: 2014-12-29T12:37:13-07:00
Authentication code: 6789

Re: batch watermarking entire directory

Post by blondzie »

Ok so I tried the Alpha mask script below, no luck. Nothing happens to the images. I guess im curious what is wrong with the first script. that I used in the past that now doesn't seem to have an affect on the images besides creating a new directory. It took me about a week to create that script and now I am finally reaching out to the community since I have very limited coding/scripting experience

mogrify -alpha Set -draw 'image Dst_In 0,0 0,0 "watermark.png"' mogrify_*.jpg
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: batch watermarking entire directory

Post by Bonzo »

As you do not say what happens to the first images except " now it no longer works" it is a bit hard to find the problem and you also need to specify your version.

I recommend going back to basics and get the watermark working on one image with direct image name input and then use that code in your batch file.
blondzie
Posts: 4
Joined: 2014-12-29T12:37:13-07:00
Authentication code: 6789

Re: batch watermarking entire directory

Post by blondzie »

Thank you both for the speedy responses, This is overwhelming for me and you two have got me going down the right path. I am operating on a windows 7 64 bit machine using the 6.9 version of Imagmagick. And that right there answers the question. The original script had only one "%" in front of my commands instead of "%%" by only typing one i was commenting out the rest of my script. when i went back and doubled all of the "%" it then worked like a charm. The peson who originally helped me was having me use CYgwin terminal and I am more comfortable with CMD line.

Thanks again guys, hope this helps anyone else running into "commenting out" problems
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: batch watermarking entire directory

Post by Bonzo »

I am glad you are sorted. Anthony has some Windows tips here: http://www.imagemagick.org/Usage/windows/

From memory you need %% in batch scripts but only % in command. Another thing to look out for is you need to use " instead of ' on Windows.
blondzie
Posts: 4
Joined: 2014-12-29T12:37:13-07:00
Authentication code: 6789

Re: batch watermarking entire directory

Post by blondzie »

Sweet thank you Bonzo!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: batch watermarking entire directory

Post by fmw42 »

mogrify -alpha Set -draw 'image Dst_In 0,0 0,0 "watermark.png"' mogrify_*.jpg
create a new directory for the results
cd to the directory you want to process
then try

Code: Select all

mogrify -path path2/newdirectory -format jpg -gravity south -draw "image over 30,30 0,0 'watermark.png'" *.jpg
change the gravity and first pair of coordinates as desired for positioning
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: batch watermarking entire directory

Post by snibgo »

When a script doesn't work, always remove "@echo off". Then you can see what is happening.

Yes, for Windows BAT scripts, each % in the OP needs doubling. This doesn't of course mean that % should always be doubled. It isn't doubled for environment variables or numbered parameters (eg %WW% and %1). See my pages for many examples of Windows BAT scripts.
snibgo's IM pages: im.snibgo.com
Post Reply