Merge an animated gif over a static png at a specific location using ImageMagick - animation

I have managed to paste an animated gif over a static png and obtained an animated gif from
those sources with the following command.
convert canvas.png animation.gif test.gif
and it works, but the animation and the canvas share the upper left corner, which is not what I want.
By reading a little I discovered that I have to use either the -composite option or the command, but I have not found examples of the right syntax to use.
I tried this:
convert canvas.png animation.gif -geometry +780+275 -composite test01.gif
which gives a static image with just the first frame of animation.gif
I tried other syntax but just produces errors.
What is the right way to accommodate the animation?

Try the following in Imagemagick. It takes a special null: operator to separate the two images and -layer composite. Also you must use -page or -set page rather than -geometry when using -layers composite. The following is Unix syntax. For Windows, remove the \ before the parentheses.
convert canvas.png null: \( animation.gif -coalese -set page +780+275 \) -layers composite -layers optimize test01.gif

Related

ImageMagick: make changes with stack B1B2B3 before composite with image A

I use the following string to composite each of B images with A:
convert A null: B*.png -gravity center -layers composite AB%d.png
The result is AB1, AB2 and AB3 and it's ok.
The next case is to make some changes with B stack, before it's composed with A. EG: -flop, -level, etc. It's also important to keep "AB%d.png" naming pattern.
How the command line should looks to do this preliminary changes with B stack and keep naming patten?
In general, ImageMagick commands have "settings" and "operators" and things that create canvases.
"Settings" are things like the background colour, the fill colour, the gravity and these settings stay set from the point you write them on the command line till the end and apply to everything that follows to the right.
"Operators", like -crop and -append actually change some aspect of an image and apply to everything currently in the stack of images - i.e. everything to the left of where they occur.
Things that create their own canvas to draw on can be recognised because they generally have a colon in them, so xc:, gradient: and label: all create canvas.
If you want to stop operators applying to too much stuff to their left, you have a couple of ways of doing that. Either create the stuff you want to manipulate first and manipulate it, then add the other stuff afterwards:
convert ChangeMe.png AndMe.png -crop XYZ -level XYZ LeaveMeUnchanged.png -composite ...
and possibly use +swap afterwards to re-order.
Or, use parentheses so that operators only apply to a limited subset of the stack:
convert LeaveMeUnchanged.png \( ChangeMe.png AndMe.png -crop \) ...
So, in answer to your specific question:
convert A null: \( B*.png -flop -level ... \) ...

Copyright/Watermark many images with different resolutions (with ImageMagick)

i am trying to solve the following problem:
I have one picture logo.png with a resolution of 1260x1580. I want to use this to copyright different JPG-Images, e.g. image1.jpg with a resolution of 1280x853. I want to have the logo e.g. at the bottom right and always with a height of e.g. 1/8 of the height of the JPG-Image.
Short: I have many images with different resolutions and the copyright should have always the same proportion (e.g. 1/8 of the total heigth) within that image.
I am using ImageMagick on command-line (on Windows 10), at the moment like this:
magick image1.jpg logo.png -resize x%[fx:u.h/8] -gravity SouthEast -geometry +15+15 -composite outfile.jpg
Unfortunately the resize-Option with x%[fx:u.h/8] doesn't work like expected, it also resizes the JPG-Image image1.jpg. I don't know, how i can manage it to resize only the logo.png and let the size of image1.jpg untouched. When i put ( logo.png -resize x%[fx:u.h/4] ) in brackets of course u.h then refers to logo.png, this is also wrong :-/
It would be great if you can assist me a little bit to find the right command for my purpose... Thanks for your replies and help!
PS: I hope that i didn't ignored some important source or help, but i can't find the solution by myself - sorry.
You have a stack of two images, the main input and the logo. You can have your "-resize" operation work on just the logo by adding a condition to the FX expression. Start your command with something like this...
magick image1.jpg logo.png -resize x%[fx:t==1?u[0].h/8:u[0].h] ...
The expression runs once for each image in the stack. The "t" substitutes for the position of the image in the stack, the first image is 0, the second is 1. So if "t" equals 1, it's the logo. Resize it to 1/8 the height of the first image indicated by "u[0].h/8". Otherwise resize it to "u[0].h", which is already the height of the first image, so it won't change that one.
In Imagemagick, try simply using parenthesis to limit the operation
magick image1.jpg ( logo.png -resize x%[fx:u.h/8] ) -gravity SouthEast -geometry +15+15 -composite outfile.jpg

Pause a GIF at start and end with overlaid text to signal start and end

I have an animated GIF that shows how to reproduce a bug report. It's often difficult to tell when the GIF starts and when it ends.
How can I modify the GIF with the following options?
the first frame is paused with the words "Start" overlaid for 1 second.
the last frame is paused with the words "End" overlaid for 1 second.
If you want to do this locally or automate with a script, you can use imagemagick. I think this should work:
convert sample.gif -coalesce -gravity center -pointsize 24 -fill dodgerblue -stroke navy \
\( -clone 0 -set delay 100 -annotate 0 'Start' \) -swap 0 +delete \
\( -clone -1 -set delay 100 -annotate 0 'END' \) -swap -1 \
-layers OptimizeFrame annotated.gif
(tested on linux, maybe you don't need to escape brackets with \ if you are running windows, I'm not sure)
If you need to process just one GIF, can easily do this online - upload the GIF in http://ezgif.com/maker, set the delay time for the first and last frame to 100, and then add the text with "write" tool, it will provide an interface for fonts, sizes, colors, text placement, but basically does the same thing.
You can insert any number of frames/extensions you need as GIF is not broken by this. See
How to find where does Image Block start in GIF images?
render start and end message frames and save booth as static GIF
extract the LZW image from GIF (remove header and extensions blocks)
write a script that inserts your frames as first and last frame of targeted GIF
To ensure 1sec pause you can use _gfxext before/after the inserted frame with Delay property set ... The only problem may be the palette for your inserted frames. If local palette is present then there is no problem. If you got only global palette instead then the message could have wrong colors ...

Add an image as a background to a previously manipulated image with Imagemagick

I'm writing a script that:
Scales
Crops
Adds a background image
to a series of around 400 transparent PNGs. I'd like to make this run as fast as possible.
Currently I've got it as two separate commands:
convert $input.png -scale $scale% -gravity Center -crop 640x640+0+0 +repage $output.png
composite -gravity center $output.png $background $output.png
Is there a way to reduce this to a single command? I've been looking at the docs for -composite but I can't see a way to add an image as the background after doing the other manipulation.
Any ideas? Thanks
Why don't you just use a && between the two commands? The second command will get executed when the furst exits without an error... Should work...

Need a tool to set multiple image backgrounds to transparent

I'm searching for a software/tool to set the image background (black) to transparent.
I want to to remove all the black and make the image transparent.
All the images are .PNG and I have around 191 hence why I need a tool to do multiple images otherwise it could take me a very long time.
Use either graphicsmagick or imagemagick mogrify tool with the -transparent black option. When I ran it on your single sample image it looked like this:
gm mogrify -transparent black 'sprite sheet 4.png'
To do a few hundred of these, you'd use it like this:
for f in *.png ; do gm mogrify -transparent black "$f" ; done
Be sure to work on copies of the files -- mogrify modifies files "in place".

Resources