Animation from a single image

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
Rafael Adorna
Posts: 4
Joined: 2011-12-28T02:30:12-07:00
Authentication code: 8675308

Animation from a single image

Post by Rafael Adorna »

Hello everyone,

first of all, thanks for reading this. Second, sorry for any mistake I do in this post, english isn't obviously my native language.
Going to the point, i would like to generate an animated image from a single image.
Explaining it further, imagine you have a huge image, like 4000x1080 and I just want the animation start from the left in a standard HD (1920x1080) and then go smoothly to the right.
Any ideas?

Thx for any reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Animation from a single image

Post by fmw42 »

You don't say what version of IM you are using nor what platform.

Basically you create a loop to subsection the images, set the delay and loop and add each new subsection as a new frame to the animation. There may be more elegant ways to do this, but this should give you the basic idea. I am not an expert on animations.
Note that -crop could be used in place of the [...] subsection concept.

For unix, try this example

infile="logo:"
ww=`convert $infile -format "%w" info:`
sub=100
convert logo:[${sub}x${sub}+0+0] +repage animation.gif
xoff=100
while [ $xoff -lt $((ww-sub)) ]; do
convert -delay 50 animation.gif ${infile}[${sub}x${sub}+$xoff+0] +repage -loop 0 animation.gif
xoff=$((xoff+sub))
done

If you want the pieces to move across a white background, then remove the +repage from both places and add -dispose previous and -background white.

infile="logo:"
ww=`convert $infile -format "%w" info:`
sub=100
convert logo:[${sub}x${sub}+0+0] animation.gif
xoff=100
while [ $xoff -lt $((ww-sub)) ]; do
convert -background white -dispose previous -delay 50 animation.gif ${infile}[${sub}x${sub}+$xoff+0] -loop 0 animation.gif
xoff=$((xoff+sub))
done

See
http://www.imagemagick.org/Usage/anim_basics/


Let us know if either of these are what you want or how you need it changed.

If on Windows, then see http://www.imagemagick.org/Usage/windows/. Unfortunately, I am not a Windows user, so cannot help in converting the syntax.
Rafael Adorna
Posts: 4
Joined: 2011-12-28T02:30:12-07:00
Authentication code: 8675308

Re: Animation from a single image

Post by Rafael Adorna »

Hi! Thanks for the reply, mate.
I was planning to run all the code that you replied in a bash script. I'm using Ubuntu 10.4 with ImageMagick 6.6.2-6 2011-03-16 Q16.
Thanks for the code, but i dunno what to do with it! A bit newbie here. Is it PERL or something?
Rafael Adorna
Posts: 4
Joined: 2011-12-28T02:30:12-07:00
Authentication code: 8675308

Re: Animation from a single image

Post by Rafael Adorna »

Ok, i figured it was a bash script (Sorry for dumbness) and it worked perfectly. Thanks a lot, mate!
Rafael Adorna
Posts: 4
Joined: 2011-12-28T02:30:12-07:00
Authentication code: 8675308

Re: Animation from a single image

Post by Rafael Adorna »

By the way, the code ended like this when I adjusted the params:

Code: Select all

infile="test.gif"
ww=`convert $infile -format "%w" info:`
sub=1920
convert -size 1920x1080 xc:transparent fondotrans.gif
xoff=0
inc=10
while [ $xoff -lt $((ww-sub)) ]; do
	convert -background transparent -gravity South -delay 10 fondotrans.gif ${infile}[${sub}x${sub}+$xoff+0] +repage -loop 0 fondotrans.gif
	xoff=$((xoff+inc))
done
Post Reply