Page 1 of 1

Generate animated Gif with one command without inteference

Posted: 2009-01-09T11:52:53-07:00
by ravel
Hi,

I want to use IM to generate gifs dynamically in a website (ASP.NET). The following source seems to create 4 gif files temporary in 4 commands and use a 5th command to merge them. I am afraid that this approach could fail when multiple users generate gifs at the same time so IM could get mixed up with the temporary files. And my tests shows that this problem occurs.

Here is the code (source: http://www.ioncannon.net/linux/81/5-ima ... es-part-1/):

Code: Select all

convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 1' flower_frame1.gif
convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 2' flower_frame2.gif
convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 3' flower_frame3.gif
convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 4' flower_frame4.gif
convert -delay 100 -size 100×100 \
   -page +0+0 flower_frame1.gif \
   -page +0+0 flower_frame2.gif \
   -page +0+0 flower_frame3.gif \
   -page +0+0 flower_frame4.gif \
   -loop 0 flower_animation.gif
Is it possible to execute all command in one go?

Thanks,
ravel

Re: Generate animated Gif with one command without inteference

Posted: 2009-01-09T12:35:00-07:00
by fmw42
ravel wrote:Hi,

I want to use IM to generate gifs dynamically in a website (ASP.NET). The following source seems to create 4 gif files temporary in 4 commands and use a 5th command to merge them. I am afraid that this approach could fail when multiple users generate gifs at the same time so IM could get mixed up with the temporary files. And my tests shows that this problem occurs.

Here is the code (source: http://www.ioncannon.net/linux/81/5-ima ... es-part-1/):

Code: Select all

convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 1' flower_frame1.gif
convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 2' flower_frame2.gif
convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 3' flower_frame3.gif
convert flower.jpg -resize 100×100 -font courier -fill white -pointsize 20 -annotate +50+50 'Frame 4' flower_frame4.gif
convert -delay 100 -size 100×100 \
   -page +0+0 flower_frame1.gif \
   -page +0+0 flower_frame2.gif \
   -page +0+0 flower_frame3.gif \
   -page +0+0 flower_frame4.gif \
   -loop 0 flower_animation.gif
Is it possible to execute all command in one go?

Thanks,
ravel

See clone and parenthesis processing at http://www.imagemagick.org/Usage/basics/ BUT Anthony needs to correct that link. It is now misdirected.


This works for me:

original:
Image

convert \( flower.jpg -resize 100x100 \) \
-font helvetica -fill white -strokewidth 2 -pointsize 20 -delay 100 \
\( -clone 0 -annotate 0x0+20+50 'Frame 1' \) \
\( -clone 0 -annotate 0x0+20+50 'Frame 2' \) \
\( -clone 0 -annotate 0x0+20+50 'Frame 3' \) \
\( -clone 0 -annotate 0x0+20+50 'Frame 4' \) \
-delete 0 -loop 0 flower_animation.gif

Image


Anthony likely can suggest a better method and/or more optimized. I am not really an expert on animation.

Re: Generate animated Gif with one command without inteference

Posted: 2009-01-09T12:55:36-07:00
by ravel
Hi,

a stupid question: What do all theses backslashes \ mean?
I am executing this command on a german windows vista cmd.exe and get errors when executing this command.
In the example i posted i had to remove all the \ and place the command into one line.

I cant get this example to run. Either the \ or the brackets ( ) makes trouble.

Thanks,
ravel

Re: Generate animated Gif with one command without inteference

Posted: 2009-01-09T13:01:10-07:00
by fmw42
ravel wrote:Hi,

a stupid question: What do all theses backslashes \ mean?
I am executing this command on a german windows vista cmd.exe and get errors when executing this command.
In the example i posted i had to remove all the \ and place the command into one line.

I cant get this example to run. Either the \ or the brackets ( ) makes trouble.

Thanks,
ravel

The \ by themselves are unix line continuations. For windows you can remove them and have one long line. The \( ... \) are parenthesis processing. You can also remove the \ and just have ( ... ) on windows.

The -clone 0, clones the processing of the flower image to reduce its size from the first parenthesis. That first processing step then needs to be deleted with the -delete 0 before merging your four cloned and annotated images into the animation.

Windows may need special escape in various places using ^.
See http://www.imagemagick.org/Usage/api/#windows
This page also discusses the backslash and parenthesis on windows.

Re: Generate animated Gif with one command without inteference

Posted: 2009-01-09T13:11:59-07:00
by ravel
Thanks, that works!

Maybe Anthony can post a comment too.

Re: Generate animated Gif with one command without inteference

Posted: 2009-01-09T23:56:22-07:00
by anthony
It seems to be covered though you may like to look at the other animation discussion also going on at this time.

As for the \ at the end. Under windows you can replace them with ^
for the same effect.

See IM Examples, API's and Scripting, Windows
http://www.imagemagick.org/Usage/api/#windows

Which lists the changes and difference in shell syntax between UNIX shell script and windows DOS script.