Add mutliple gifs to one background - imagemagick

I'm attempting to "play" the same gif, all at once, in multiple areas of a same, single, image.
Reading thru the documentation for IM v6, there are no examples of this. I have also attempted chaining separate 'convert' composite commands without any luck.
Is it possible to do this in one command or multiple?

In ImageMagick, you can use null: and -layers composite to combine multiple animations onto one background image. But each animation must have the same number of frames and delays. For example in unix syntax with new line character \ (replace with ^ for Windows):
convert -size 512x512 xc:black \
null: morph_anim_1pt.gif -gravity northwest -geometry +50+50 -layers composite \
null: morph_anim_1pt.gif -gravity southwest -geometry +50+50 -layers composite \
null: morph_anim_1pt.gif -gravity southeast -geometry +50+50 -layers composite \
null: morph_anim_1pt.gif -gravity northeast -geometry +50+50 -layers composite \
morph_anim_1pt_animation.gif
See http://www.imagemagick.org/Usage/anim_mods/#composite

Related

How can I combine multiple pngs as well as animated gifs in Imagemagick

I have 5 transparent images and 1 animated gif
All of them have the same dimensions of 1500 x 1500 px
I need to combine them in a way that they are overlayed on top of each other
FOR EG.
body.png clothing.png jewellery.gif(24 frames)
I have tried this but the first frame is missing the clothing and the jewellery only comes from the 3rd frame
convert body.png clothing.png null: jewellery -coalesce -composite -layers optimize result.gif
If you want to overlay all of the 5 transparent images onto every frame of the animated GIF, then try:
Unix syntax:
convert \( image1 image2 ... image5 -background none -flatten \) null: \( animation.gif -coalesce \) -layers composite -layers optimize new_animation.gif
Windows syntax:
convert ( image1 image2 ... image5 -background none -flatten ) null: ( animation.gif -coalesce ) -layers composite -layers optimize new_animation.gif
Use your actual file names.
If on ImageMagick 7, use magick in place of convert.

Apply rounded corners to gif with ImageMagick

I have a bunch of animated gifs that I would like to add rounded corners to. I have looked at this page:
http://www.imagemagick.org/Usage/thumbnails/#rounded
But unable to get the rounded corners to apply to an animated gif. Is it possible to do this with ImageMagick? Any help would be appreciated!
In Imagemagick, you need to use -layers composite with a null: separator as follows:
Unix Syntax:
Input:
convert animation.gif -coalesce \
null: \
\( animation.gif[0] -alpha extract \
-draw 'fill black polygon 0,0 0,15 15,0 fill white circle 15,15 15,0' \
\( +clone -flip \) -compose Multiply -composite \
\( +clone -flop \) -compose Multiply -composite \
\) \
-alpha off -compose CopyOpacity \
-layers composite \
-layers optimize \
animation_rounded.gif
See https://imagemagick.org/Usage/anim_mods/#composite
Because your output is GIF, which only supports binary transparency (off or on full), the corners will not be smoothly rounded.

How to place a GIF on another GIF with ImageMagick, where both GIFs are of different sizes

I have two GIFs of different sizes. I want to be able to place one animated GIF onto a static background GIF at a specific location and at the same time add text to the result. I am new to ImageMagick world, please help.
I am trying to achieve the following result where dog sticker is in a separate GIF.
If your two animations do not have the same delay and number of frames, see https://www.imagemagick.org/Usage/anim_mods/#merging.
If your animations have the same delay and number of frames, you can do (unix syntax):
Background:
Animation1:
Animation:2
convert skyblue.gif \
null: \
\( morph_anim_1pt.gif -coalesce \) \
-gravity northwest -geometry +20+20 -compose over -layers composite \
null: \
\( morph_anim_5pts.gif -coalesce \) \
-gravity southeast -geometry +20+20 -compose over -layers composite \
-layers optimize \
result.gif
See https://www.imagemagick.org/Usage/anim_mods/#composite and subsequent sections.
Perhaps this is more what you want. Imagemagick command line code in unix syntax:
The background animation has 3 frames and foreground one has 11 frames. So I repeat the background 4 times and remove the last frame so there is a total of 11 frames for the background. I coalesce the animation and add text to each frame using -annotate. Then I use -layers composite to overlay the foreground animation onto the background.
Background:
Foreground:
convert -delay 20 \
\( glitter_blue_tiled.gif glitter_blue_tiled.gif \
glitter_blue_tiled.gif glitter_blue_tiled.gif \
-coalesce \
+delete \
-font arial -pointsize 28 -fill black -gravity north \
-annotate +0+20 "TESTING" \) \
null: \
\( coalesced_k.gif -coalesce \) \
-gravity south -geometry +0+20 \
-compose over \
-layers composite \
-layers optimize \
-loop 0 \
result2.gif

ImageMagick apply watermark multiple times

Currently, with ImageMagick I apply watermark.png on top of picture.jpg in the center using:
convert -size 700x1300 -composite picture.jpg watermark.png -gravity center -geometry 700x1300 output.jpg
This nicely overlays my watermark in the middle of the image. However, I want to achieve this effect in the top-left, center, and bottom-right. I've tried combining multiple -composites with no result. I would like to avoid calling 3 different commands to avoid the extra overhead it introduces, but I'm starting to believe it isn't possible without doing so.
What can I do to achieve the three watermark positions in one command, NorthWest, Center and SouthEast?
Hold the watermark image in a memory register with "-write mpr:watermark", then recall it into your command for the second and third composite. Here's a simple example of how that works...
convert watermark.png -write mpr:watermark input.png +swap \
-gravity center -composite mpr:watermark -gravity northwest -composite \
mpr:watermark -gravity southeast -composite output.png
Set the geometry before each composite if necessary to give the mark some padding from the corners.
In Imagemagick, there is a -gravity setting that allows you to put the watermark in various locations specified by the compass directions. See http://www.imagemagick.org/script/command-line-options.php#gravity. However, your syntax is not proper and may fail for use with IM 7. The proper syntax is to read the input image first. So your command should be
convert background watermark -gravity center -compose over -composite output
Change center to one of the other gravity settings such as northwest or southeast
Also your -size does nothing in your command. If you want to use -size WxH xc:somecolor, then you would use that in place of the background.
If you want to resize, then do not use -geometry. That is typically used for offsetting the gravity placement. Use -resize WxH if you want to resize the result.
See
http://www.imagemagick.org/Usage/compose/#compose
http://www.imagemagick.org/Usage/layers/#convert
I would modify GeeMack's answer just slightly so it reads a bit more symmetric:
convert watermark.png -write mpr:watermark +delete \
input.png \
mpr:watermark -gravity center -compose over -composite \
mpr:watermark -gravity northwest -compose over -composite \
mpr:watermark -gravity southeast -compose over -composite \
output.png
EDITED: to followup with OP question. If you need to resize the watermark, then do
convert watermark.png -resize 700x1300 -write mpr:watermark +delete \
input.png \
mpr:watermark -gravity center -compose over -composite \
mpr:watermark -gravity northwest -compose over -composite \
mpr:watermark -gravity southeast -compose over -composite \
output.png

How to use ImageMagick to place a watermark in multiple locations on an image

I am currently using imagemagick through the command line to place a watermark in multiple locations on another image, but the way I am doing it seems like it probably isn't the best way to go about doing it.
Here is how I am doing it:
exec("convert 'originalImage.jpg' 'watermark.jpg' -gravity NorthWest -geometry +3+3 -define compose:args=30,100 -compose dissolve -composite 'finalImage.jpg'");
exec("convert 'finalImage.jpg' 'watermark.jpg' -gravity NorthEast -geometry +3+3 -define compose:args=30,100 -compose dissolve -composite 'finalImage.jpg'");
exec("convert 'finalImage.jpg' 'watermark.jpg' -gravity SouthWest -geometry +3+3 -define compose:args=30,100 -compose dissolve -composite 'finalImage.jpg'");
This is (1) taking originalImage.jpg and adding watermark.jpg to the top-left corner (with a 3px margin from the top left, using 30% opacity), then (2) taking that resulting finalImage.jpg and adding the watermark to the top-right corner, and then (3) taking that finalImage.jpg again and adding the watermark to the bottom-left corner.
So it is recreating the file three times to come up with the final image. Is there a shorthand way to do this same thing without having to save the file three separate times?
Thanks!
Here is another solution using multiple "-draw" options:
"-draw" doesn't have a "dissolve" option so you'd need to prepare the
watermark image ahead of time to have 30% alpha.
convert watermark.jpg -alpha set -channel alpha -fx .30 watermark30.png
convert originalImage.jpg \
-gravity NorthWest -draw "image over 3,3 0,0 watermark30.png" \
-gravity NorthEast -draw "image over 3,3 0,0 watermark30.png" \
-gravity SouthWest -draw "image over 3,3 0,0 watermark30.png" \
finalImage.jpg
You could combine this with Mark's good recommendation to use the MPR format instead of watermark30.png. I did a couple of "-draw" versus "-composite" timing tests, and it appears that Mark's method is somewhat faster.
I hope you don't mind my editing your post - delete it if you wish - but here is how a single command might look that does the same all in one go:
convert watermark.jpg -alpha set -channel alpha -fx .30 -write MPR:wm30 +delete original.jpg \
-gravity NorthWest -draw "image over 3,3 0,0 'MPR:wm30'" \
-gravity NorthEast -draw "image over 3,3 0,0 'MPR:wm30'" \
-gravity SouthWest -draw "image over 3,3 0,0 'MPR:wm30'" \
finalImage.jpg
Not at a computer, so untested, but this should be close:
convert originalImage.jpg \( watermark.jpg -write MPR:wm \) \
-define compose:args=30,100 -compose dissolve \
-gravity NorthWest -geometry +3+3 -composite \
MPR:wm -gravity NorthEast -geometry +3+3 -composite \
MPR:wm -gravity SouthWest -geometry +3+3 -composite finalImage.jpg
MPR is a RAM-based "Magick Persistent Register" which I use to avoid needing to keep re-reading the watermark.jpg.
The compose arguments persist until changed, so I don't repeat them. It may not be necessary to repeat the second and third -geometry.

Resources