Overlaying an image on multiple images

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
Demian
Posts: 9
Joined: 2012-01-18T10:00:19-07:00
Authentication code: 8675308

Overlaying an image on multiple images

Post by Demian »

ImageMagick 6.7.4-2
Windows 7
Windows command-line

I'm really new to ImageMagick but I managed to extract all frames from a GIF animation. Now I would like to overlay a gif image on top of all of these frames. I know how to compile the frames back to GIF. I can overlay individual images but not all of them at once. The frames are named f_#.gif and the overlay is overlay.gif and it is the same size as the frames. I have a bit over 200 frames.

I tried this but it only wrote one "anim_0.gif" and it was full black.

Code: Select all

composite -gravity center overlay.gif f_*.gif anim_%d.gif
This code correctly writes one image with the overlay but I don't know how I would do all of them at once.

Code: Select all

composite -gravity center overlay.gif f_0.gif anim_%d.gif
Although scaling multiple images with this code works fine.

Code: Select all

convert -scale 50% f_*.gif scaled_%d.gif
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Overlaying an image on multiple images

Post by glennrp »

I would try the "mogrify" application with the "-draw image over ..." optoon
(first copy all of the GIF images into a new working directory and
run "mogrify" there, because the input images will be overwritten with the
watermarked ones).
Demian
Posts: 9
Joined: 2012-01-18T10:00:19-07:00
Authentication code: 8675308

Re: Overlaying an image on multiple images

Post by Demian »

I can't figure out how it mogrify works. Where is the input image? This is as far as I got but it gives error not to mention there is no input image.

Code: Select all

mogrify -draw 'image Over 0,0 0,0 "overlay.gif"' anim_%d.gif
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Overlaying an image on multiple images

Post by fmw42 »

Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Overlaying an image on multiple images

Post by Bonzo »

Try this

Code: Select all

convert animation.gif -coalesce -gravity South -geometry +0+0 null: watermark.png -layers composite -layers optimize watermarked_animation.gif
Refresh this page to see the example again.
Image
Demian
Posts: 9
Joined: 2012-01-18T10:00:19-07:00
Authentication code: 8675308

Re: Overlaying an image on multiple images

Post by Demian »

Bonzo wrote:Try this

Code: Select all

convert animation.gif -coalesce -gravity South -geometry +0+0 null: watermark.png -layers composite -layers optimize watermarked_animation.gif
Oh my. That worked. Thanks!

Any idea how to make individual frames longer in a gif? For example frame 1 would be 2 seconds long, frames 2-100 4ms and frame 101 10 seconds?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Overlaying an image on multiple images

Post by anthony »

You can also use -layers composite to overlay one image over a large number of images already in memory.

EG:
convert logo: granite: null: rose: -geometry +10+10 -layers composite images_%d.png

This overlays the rose image onto two images.

See IM Examples...
http://www.imagemagick.org/Usage/anim_mods/#composite
and specifically the next section on the operators special handling when only one image is provided in one of the two image lists (separated by the special "null:" marker image)
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply