Generate animated Gif with one command without inteference

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
ravel

Generate animated Gif with one command without inteference

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generate animated Gif with one command without inteference

Post 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.
ravel

Re: Generate animated Gif with one command without inteference

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Generate animated Gif with one command without inteference

Post 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.
ravel

Re: Generate animated Gif with one command without inteference

Post by ravel »

Thanks, that works!

Maybe Anthony can post a comment too.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Generate animated Gif with one command without inteference

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply