This simple snippet can be used for creating animated gif images with swirl effects. I was bored at home and saw that ImageMagick was installed in my machine. 🙂 So started playing with that. 🙂
The shell script will create the second image from the first image shown below.
declare -i I
while [ $I -lt $FRAMES ]
NAME=`echo "$I*$ROTATEANGLE" | bc`;
convert -$OPTION "$NAME" "$FILENAME" "$OPTION"_"$NAME".png
convert -coalesce -dither -colors 32 -layers optimize $COMMANDOPTION hari-opt-32.gif
The code is pretty simple once you know the options for convert command of ImageMagick.
ImageMagick doc says the following for convert command. “convert between image formats as well as resize an image, blur, crop, despeckle, dither, draw on, flip, join, re-sample, and much more.” Well, seriously, there is MUCH MORE. 🙂
The option to swirl an image is swirl. It takes angle by which the images has to be swirled as the parameter.
So the following command swirls the image by 90 degrees.
convert -swirl 90 src.png dest.png
To create an animated GIF using a set of png images, we use the coalesce option. The following command creates output.gif using three PNG files (input1.png, input2.png and input3.png). To reduce the file size, use the options like dither, colors and layers. The more colors you have in your image, the more will be the file size. For example, in the following snippet, the second commands generates a GIF file which is small in size compared to the first GIF file.
convert -coalesce input1.png input2.png input3.png output.gif
convert -coalesce -dither -colors 32 -layers optimize input1.png input2.png input3.png output-compressed.gif