Applying a mask to multiple images at the same time

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
Lio
Posts: 3
Joined: 2014-04-02T06:21:40-07:00
Authentication code: 6789

Applying a mask to multiple images at the same time

Post by Lio »

Hello. I've been trying to apply the same mask to multiple images at the same time with one command, but it only seems to affect the first image on the folder.

This is the what I'm using

Code: Select all

composite -compose CopyOpacity mask.jpg *.png
I'm not sure if composite works differently, since I've already used convert and mogrify (like the following example) and it does affect every image on the folder.

Code: Select all

mogrify -resize 500x500! *.jpg
Is what I want possible?If so, any suggestions?

Thanks a lot.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Applying a mask to multiple images at the same time

Post by fmw42 »

composite and convert -composite only work with two images at a time plus an optional mask. But you may be able to use mogrify to do it. See
http://www.imagemagick.org/Usage/basics ... fy_compose, where there is an example of what I think you may want to do.
Lio
Posts: 3
Joined: 2014-04-02T06:21:40-07:00
Authentication code: 6789

Re: Applying a mask to multiple images at the same time

Post by Lio »

Thanks for the answer, I tried that and a couple of other things there, but it doesn't seem to work if I try to use another image as the mask, it seems to be fine if I just draw a shape though. I may be doing something wrong, or maybe it's not supported.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Applying a mask to multiple images at the same time

Post by fmw42 »

Please provide an example of a couple of input images and the mask image and what you expect for the output. Perhaps I misunderstand what you are trying to do. You can upload to dropbox.com (public folder) and put links here.
Lio
Posts: 3
Joined: 2014-04-02T06:21:40-07:00
Authentication code: 6789

Re: Applying a mask to multiple images at the same time

Post by Lio »

Hey. Thanks, but I was probably doing something wrong, a friend of mine that has more scripting knowledge ended up with this script that seems to work perfectly

Code: Select all

C:\foo\bar> for /f %x in ('dir /s /b *.png') do @composite -compose CopyOpacity mask.jpg %x %~dx%~px%~nxXYZ.png
Post Reply