Suggested batch code for image watermarking?

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
user989797
Posts: 8
Joined: 2015-08-13T10:52:21-07:00
Authentication code: 1151

Suggested batch code for image watermarking?

Post by user989797 »

I successfully used:

Code: Select all

composite -compose atop -geometry +75 -gravity southeast myhubbachat1.png pic.jpg photo-watermarked.jpg
to do what I want on one image.

I want a batch file to do it on 2k/x amount of images now.

So is that one still good with a little modfication or I need something more.

Please advise.

Im not tied to that code above its just the first one I happened across.

The watermark is the same for all images and I want it in same place- bottom right corner.

Oh and I also have .gif files as well as .jpg
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Suggested batch code for image watermarking?

Post by fmw42 »

You can use mogrify to watermark all images in a folder with another image located somewhere else. See http://www.imagemagick.org/Usage/basics/#mogrify and http://www.imagemagick.org/Usage/basics ... fy_compose.

I always create a new directory for the output and use the -path option.

So it would be something like

assume input directory is folder1 and has only images in it (such as gif and jpg and png, etc, no text files)
assume the watermark image is watermark.png (but it can be gif or jpg)
create a new empty directory of folder2
change directory to folder1

Code: Select all

mogrify -path path2/folder2 -format jpg -gravity southeast -draw 'image over 0,0 0,0 "watermark.png"' *
user989797
Posts: 8
Joined: 2015-08-13T10:52:21-07:00
Authentication code: 1151

Re: Suggested batch code for image watermarking?

Post by user989797 »

thanks, but is that only for jpgs? do i have to make a second one for the gifs?

Im still very new to this :)

Oh i see what the format thing is for to make a new file rather than overwrite, but what if it was an animalted gif it would then be saved as a static jpg wouldnt it which i dont want.

Wouldnt it be easier to overwite original file in that case rather than write to new file cos then extention would stay the same?

Edit: I got it. Mixed your code with some from another thread I was reading. This did what I wanted:

Code: Select all

mogrify -gravity southeast -draw "image over 0,0 0,0 'watermark.png'" *
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Suggested batch code for image watermarking?

Post by fmw42 »

If you overwrite the image rather than create a new directory, you run the risk of destroying your original data by bad coding. The -format jpg was because I assumed you wanted jpg output from your example. I am not sure if mogrify will watermark very frame in an animated gif. I have not tested it. It might work. But you may have to use other techniques. See http://www.imagemagick.org/Usage/anim_m ... mpose_draw
user989797
Posts: 8
Joined: 2015-08-13T10:52:21-07:00
Authentication code: 1151

Re: Suggested batch code for image watermarking?

Post by user989797 »

Well Im using copies so i dont see the problem?

The gifs took a while and were cpu intensive but seemed to work.
Post Reply