Animated gif with slide transition?
-
- Posts: 2
- Joined: 2016-07-29T16:27:42-07:00
- Authentication code: 1151
Animated gif with slide transition?
Hello,
I'm wondering if it's possible, and how, to create an animated gif from a sequence of images where each image slides to the left off the frame as the next image slides in?
Thanks!
I'm wondering if it's possible, and how, to create an animated gif from a sequence of images where each image slides to the left off the frame as the next image slides in?
Thanks!
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Animated gif with slide transition?
Sure, it's possible. Each output frame is a crop of two input frames that are appended sideways. The WxH of the crop is the same size as the inputs, the crop y-offset is zero, and the crop x-offset varies from one frame to the next.
This is easily done in a script. In v7, you can probably create the entire sequence in a single command.
Instead of crop, you can use "-distort" with a viewport.
This is easily done in a script. In v7, you can probably create the entire sequence in a single command.
Instead of crop, you can use "-distort" with a viewport.
snibgo's IM pages: im.snibgo.com
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Animated gif with slide transition?
As snibgo mentioned, using ImageMagick 7 it can be done in a single command with just a handful of individual operations.poke53281sys64738 wrote:I'm wondering if it's possible, and how, to create an animated gif from a sequence of images where each image slides to the left off the frame as the next image slides in?
Consider the total layers in the final GIF would be the number of input images multiplied by the number of steps moving from one image to the next. A smooth transition could be dozens or hundreds of GIF layers. Even with small sized input images you could end up with a pretty large output file size.
The command or script would depend on your version of IM and the operating system you're working on.
-
- Posts: 2
- Joined: 2016-07-29T16:27:42-07:00
- Authentication code: 1151
Re: Animated gif with slide transition?
snibgo and GeeMack, thank you both for your responses, helped a lot and I came up with something like this to do the sort of thing I want:
takes a series of images, resizes to 192px wide, and appends them all together. then starts moving along the appended image cropping by the 192px width, pausing for 1s on the first, then moving more quickly along until it gets to the 2nd, another 1s, pause, etc.
i expect there could be more elegant ways to do this, not sure if there's some kind of loop construct that can be used to iterate the individual clone/crop commands? but for now this works and I can write a script to generate the full command based on desired input/output.
thanks again!
ken
Code: Select all
convert \( 1MuEL6cu.* -resize 192x +append \) \( -clone 0 -crop 192x+0+0 -set delay 100 \) \( -clone 0 -crop 192x+48+0 -set delay 25 \) \( -clone 0 -crop 192x+96+0 \) \( -clone 0 -crop 192x+144+0 \) \( -clone 0 -crop 192x+192+0 -set delay 100 \) \( -clone 0 -crop 192x+240+0 -set delay 25 \) \( -clone 0 -crop 192x+288+0 \) \( -clone 0 -crop 192x+336+0 \) -delete 0 -loop 10 +repage test.gif
i expect there could be more elegant ways to do this, not sure if there's some kind of loop construct that can be used to iterate the individual clone/crop commands? but for now this works and I can write a script to generate the full command based on desired input/output.
thanks again!
ken
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Animated gif with slide transition?
Using ImageMagick 7 on Windows 10 I can do this at a command prompt and make the entire animated GIF in one command...poke53281sys64738 wrote:i expect there could be more elegant ways to do this, not sure if there's some kind of loop construct that can be used to iterate the individual clone/crop commands? but for now this works and I can write a script to generate the full command based on desired input/output.
Code: Select all
magick ^
*.jpg ^
-set option:frames %[fx:(n*4)-1] ^
-gravity center ^
-resize 200x200^^ ^
-extent 200x200 ^
( -clone 0 ) ^
+append ^
-duplicate %[frames] ^
-define distort:viewport=200x200 ^
-distort affine "%[fx:t*(200/4)],0 0,0" ^
-set delay %[fx:t%4?10:500] ^
-loop 0 ^
-layers optimize ^
output.gif
This almost surely will not work with ImageMagick 6.
You'd have to translate that to *nix shell syntax by using "\" instead of "^" as continued line characters, probably escaping parentheses with "\", not escaping the "^" on the "-resize" operation, and changing any double quote marks to single quotes. I haven't tried it on a *nix shell, so it might need a couple other tweaks, too.
Last edited by GeeMack on 2016-08-08T18:45:07-07:00, edited 2 times in total.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Animated gif with slide transition?
Downside is it uses a lot of memory for all the repeats of the strip. But it is a nice implementation in IM 7.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Animated gif with slide transition?
One thought might be to use -roll and a fixed crop with a clone or mpr that could be re-written and deleted as needed.
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Animated gif with slide transition?
Distort can be used to create a animated crop in IMv6 as it was shown above.
But you should be able to do the same thing directly using crop in IMv7 "magick"
But I do not have time (or setup) to work it out at this time.
Remember the big feature of IMv7 is that 'percent escapes' should be able to be used in almost all operations, not just specific ones (like -distort and -set) as in IMv6
But you should be able to do the same thing directly using crop in IMv7 "magick"
But I do not have time (or setup) to work it out at this time.
Remember the big feature of IMv7 is that 'percent escapes' should be able to be used in almost all operations, not just specific ones (like -distort and -set) as in IMv6
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Animated gif with slide transition?
An alternative idea. is to make use of the GIF 'previous' disposal.
That is start with one image with a disposal of 'none', then all later frames are just the part of the image that 'overlays' that static background, as partial frames. Should be a lot smaller and faster than generating the full image each time.
Now a 'wipe' animation is actually even easier (and very small GIF file wise), as that is just overlaying frames consisting of just 'slivers' of the overlay image (which is what a 'tile crop' generates!)
convert rose: \( -clone 0 -flip -crop 5x0 \) -set delay 20 miff:- | animate -
and with the flip back again...
convert rose: \( -clone 0 -flip -crop 5x0 \) \( -clone 0 -crop 5x0 \) -set delay 20 miff:- | animate -
Just added it to IM examples.. Wonder why I never thought of it years ago!
http://www.imagemagick.org/Usage/anim_mods/#wipe
That is start with one image with a disposal of 'none', then all later frames are just the part of the image that 'overlays' that static background, as partial frames. Should be a lot smaller and faster than generating the full image each time.
Now a 'wipe' animation is actually even easier (and very small GIF file wise), as that is just overlaying frames consisting of just 'slivers' of the overlay image (which is what a 'tile crop' generates!)
convert rose: \( -clone 0 -flip -crop 5x0 \) -set delay 20 miff:- | animate -
and with the flip back again...
convert rose: \( -clone 0 -flip -crop 5x0 \) \( -clone 0 -crop 5x0 \) -set delay 20 miff:- | animate -
Just added it to IM examples.. Wonder why I never thought of it years ago!
http://www.imagemagick.org/Usage/anim_mods/#wipe
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/
- GeeMack
- Posts: 718
- Joined: 2015-12-01T22:09:46-07:00
- Authentication code: 1151
- Location: Central Illinois, USA
Re: Animated gif with slide transition?
That looks pretty useful. Here is an example with IM7 in Windows syntax. It shows how to set the delays so each full image pauses a fraction of a second before the next wipe begins. It also shows how to make the wipe come from the left, top, right, or bottom of the image.anthony wrote:Wonder why I never thought of it years ago!
Code: Select all
magick ^
-size 240x160 ^
gradient:green-yellow gradient:blue-purple gradient:orange-white gradient:red-black ^
-write mpr:stack -delete 0--1 ^
-delay 200 mpr:stack[0] ^
( -delay 10 mpr:stack[1] -crop 10x0 ) -delay 200 mpr:stack[1] ^
( -delay 10 mpr:stack[2] -crop 0x10 ) -delay 200 mpr:stack[2] ^
( -delay 10 mpr:stack[3] -crop 10x0 -reverse ) -delay 200 mpr:stack[3] ^
( -delay 10 mpr:stack[0] -crop 0x10 -reverse ) ^
-loop 0 wipe.gif
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Animated gif with slide transition?
Hmm I didn't know you could pull just one image out of a list saved to MPR. That is useful to know!
Added this to the examples..
Also added this to the "MPR:" examples...
http://www.imagemagick.org/Usage/files/#mpr
Added this to the examples..
Code: Select all
convert -size 100x60 -delay 100 \
gradient:green-yellow gradient:blue-purple \
gradient:orange-white gradient:red-black \
-write mpr:stack -delete 0--1 \
\
mpr:stack'[0]' \( mpr:stack'[1]' -set delay 5 -crop 4x0 \) \
mpr:stack'[1]' \( mpr:stack'[2]' -set delay 5 -crop 0x4 \) \
mpr:stack'[2]' \( mpr:stack'[3]' -set delay 5 -crop 4x0 -reverse \) \
mpr:stack'[3]' \( mpr:stack'[0]' -set delay 5 -crop 0x4 -reverse \) \
-loop 0 wipe_all.gif
Also added this to the "MPR:" examples...
http://www.imagemagick.org/Usage/files/#mpr
When you do have multiple images in "mpr:" you can actually still extract individual images from that sequence! Using "mpr:image'[2]'" will pull the third image from a multi-image sequence saved using "-write mpr:image".
For example here I extract the 'storm' image from a set of four images.
Code: Select all
convert eye.gif news.gif storm.gif tree.gif \ -write mpr:images -delete 0--1 \ \ mpr:images'[2]' mpr_extract.gif
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/