I am trying to change the background layer of a batch of png images to include a moving gif. I'm running on MacOs and imagemagick version 7.1.0-19.
There are two types of images I want to merge:
Overlay static images A*.png
Background image Moving#40.gif
The background gif takes 120 frames.
So far I have managed to build the images and create GIFs. However the animated gifs are not moving. I have tried including delay and loop but this does nothing. The code is as follows:
magick mogrify -format gif -delay 10 -draw 'image Dst_Over 0,0 0,0 "Moving#40.gif"' A*.png -loop 0
I have been looking for days for similar use cases but have not found a solution,I just recently got into ImageMagick so advice is much appreciated.
any ideas on how this can be accomplished?
One way would be to process them one at a time in a script loop, since one is a gif animation. Then you would use a null: separator and -layers composite. For example for one PNG.
Transparent PNG:
Animation:
magick logot.png null: \( glitter.gif -coalesce \) -gravity center -compose dstover -layers composite -layers optimize result1.gif
See https://legacy.imagemagick.org/Usage/anim_mods/#composite
Alternately, you can use -draw, but in the reverse with the png inside -draw and the GIF after magick.
magick glitter.gif -gravity center -draw 'image Over 0,0 0,0 "logot.png"' -layers optimize result2.gif
Related
There are two image, one is gif, another is png. Now I need to wrap the gif image with png image. I use ImageMagick and I think it may work for me.
convert src.png input.gif -gravity Center -composite des.gif;
As you see, the output is unexpected while there is a black block.
And the des.gif is not animated.
left is des.gif the right is input.gif
EDIT
Here is my test files. https://drive.google.com/drive/folders/0B-64AliLi9OnWVQyLWU3TElHNHM?usp=sharing
You have 77 frames. But the first frame is much smaller than all the rest. From Imagemagick (6.9.9.13 Q16 Mac OSX Sierra), I can see this from
identify input.gif
input.gif[0] GIF 216x384 216x384+0+0 8-bit sRGB 256c 3.20786MiB 0.010u 0:00.009
input.gif[1] GIF 1080x1920 216x384+0+0 8-bit sRGB 64c 3.20786MiB 0.010u 0:00.009
...
input.gif[76] GIF 1080x1920 216x384+0+0 8-bit sRGB 64c 3.20786MiB 0.000u 0:00.000
Also all frames but the first are near solid green. Only the first has a circle in it.
Nevertheless, if you fix your input.gif, you can composite them so all the gif frames animate over the background png using the following command:
convert image.png null: \( input.gif -coalesce \) -gravity Center -layers composite des.gif
Note that after the coalesce all frames become 216x384. That makes the overlay frames way too small. This will make all frames larger so that they fit the background. But still all will be green exact for the first.
convert image.png null: \( input.gif -coalesce -resize 1080x1920! \) -gravity Center -layers composite des.gif
See http://www.imagemagick.org/Usage/anim_mods/#background
If using Imagemagick 7, then change convert to magick.
I'm wondering how to remove and replace transparency in an animated GIF with ImageMagick.
My goal is to take several pages with different aspect ratios and make an animated GIF that cycles through them.
document1.png
I am using
convert -delay 50 -resize 212 -dispose Previous -page 212x275 -crop 212x275+0+0 +repage document1.png document2.png documents.gif 2>&1
to create the GIF.
This sizes my documents correctly, but leaves the empty space from the short images transparent, but I would like that to be white. How can I change the transparency to white?
doc.gif
I have tried
convert doc.gif -background black -alpha off doc2.gif
convert doc.gif -background black -flatten doc2.gif
-alpha doesn't seem to do anything, and -flatten removes the animation
I want to add watermark images to GIF animations with ImageMagick.
The following doesn't work: it just gives produces a weird single image with crazy colors, and the transparent-watermark.png doesn't seem to be there at all.
composite -compose Dst_Over background-gif.gif transparent-watermark.png final.gif
How can this be accomplished? It's similar to annotating but with an image instead of text.
convert background-animation.gif -coalesce -gravity NorthEast -draw 'image over 0,0 0,0 "transparent-watermark.png"' -layers Optimize final.gif
I've had same problem with
convert -delay 4 -loop 0 *.png animated.gif
And fix it adding -alpha remove
convert -delay 4 -loop 0 *.png -alpha remove animated.gif
Try -alpha remove or -background white(other cases) to fix it.
I have two images. One is background with no alpha. The other is a white cloud. The alpha of the cloud image is premultiplied with black. When I composite them the white cloud has black in it, so it looks grey instead of white like it should. I'm doing:
convert -gravity Center bg.tga whitecloud.tga -composite comp.tga
Is there a way to composite premultiplied images in ImageMagick, or does the image have to be non-premultiplied? Can I make a premultiplied image non-premultiplied using ImageMagick?
Update:
Ok, here are the images as TGA for download:
http://acatysmoof.com/posting/problems/imagemagick/premultiplication/bg.tga
http://acatysmoof.com/posting/problems/imagemagick/premultiplication/whitecloud.tga
http://acatysmoof.com/posting/problems/imagemagick/premultiplication/aftereffects.tga
http://acatysmoof.com/posting/problems/imagemagick/premultiplication/imagemagick.tga
and in the same order as jpgs to view in your browser:
I tried all the modes provided, but none of them create the same result as After Effects.
It would be easier if you showed your images, but try adding -compose lighten before -composite in your command, like this:
convert a.tga b.tga -compose lighten -composite out.tga
Basically that will make ImageMagick choose the lighter pixel of the two images at every point.
If that doesn't work, try other blending modes
for b in $(identify -list compose); do
convert -label "$b" bg.tga whitecloud.tga -compose $b -composite miff:-
done | montage - -tile 5x out.png
I am kind of thinking Atop, Dissolve, SrcAtop and SrcOver might be your friends but have a look full-size and see what floats your boat. That would be
convert a.tga b.tga -compose Atop -composite out.tga
Here is an Imagemagick command that does what you want:
convert -gravity Center whitecloud.tga -fx "u/max(u.a, 1/255)" bg.tga +swap -composite -fx "u*u.a" comp.tga
What's happening here?
-fx command #1: Convert whitecloud.tga from premultiplied alpha to "normal". The max() operator is a special case to avoid dividing by zero.
+swap command: Make bg.tga the first image and the revised whitecloud.tga the second.
-composite these two regular, non-premultiplied images.
-fx command #2: take the result, and return to a premultiplied alpha format.
This gives exactly the same result as After Effects.
Note that, as I wrote it, it only works for an opaque bg.tga. You'd need to do some extra work to handle a transparent background image.
If you want to duplicate the After Effects result, then I believe what you want to do in ImageMagick is the following -- composite the background image with a white image using the cloud as a mask:
convert bg.tga \( -clone 0 -fill white -colorize 100 \) whitecloud.tga -compose over -composite cloud_blue.tga
I have posted a JPG result, but my .tga result is the same.
I'm using ImageMagick to rotate animated gifs. Simply:
convert image.gif -rotate 32 -alpha set -background none output.gif
Output:
https://s3-eu-west-1.amazonaws.com/uploads-eu.hipchat.com/108112/892631/ATp8mXXrDdSkCNu/sowa-test2.gif
Does anyone have a clue why output image is distorted this way and how to avoid this?
Without seeing the original image, I would suggest extracting each image, apply rotation, and then re-build the animated gif.
Example using the following gif:
convert anim_none.gif -scene 1 +adjoin tmp_%02d.gif
mogrify -rotate 32 -alpha set -background none tmp_*.gif
convert tmp_*.gif -loop 0 final.gif
And note: quality is expected to degrade with rotation operations.
The solution from emcconville didn't quite work for me. Part of the issue may have been that my layers were transparent and so not all the same dimensions. However, using his solution as a base and then modifying it based on things I saw elsewhere, I was able to get my gif rotated:
convert my_gif.gif -background transparent \
-virtual-pixel background -coalesce tmp_%02d.gif
mogrify -rotate -45 -background transparent -virtual-pixel background tmp_*.gif
convert tmp_*.gif -loop 0 my_gif_rotated.gif
Hopefully this helps others.