GoAniGiffy: A versatile animated GIF creator
GoAniGiffy is a small utility written in the Go Programming language to create animated GIFs from a set of alphabetically sorted image files (eg. video frames extracted as JPEGs with MPlayer or VLC) with support for basic image editing operations like cropping, scaling, rotation & flip. Scaling & Downsampling the images for creating the GIF are performed with high quality algorithms.
Animated GIFs have made a comeback as very convenient ways to post short video clips or slideshows on the web without needing Flash, YouTube or Flickr embedding. Their convenience often outweights image quality limitations (only 256 colors palette) and poor compression for basic uses.
While a number of free web services have sprung up to convert videos to animated GIFs, they do not typically allow editing beyond basic trimming. You could use a traditional video editor of course but the free ones are not exactly intuitive and have limited utility in creating slideshows.
GoAniGiffy is a small utility written in Go Programming language that was born out of the need to convert my demo video of ArdGrafix6100 into an animated GIF for hosting on GitHub Pages. This video was originally shot on a phone camera and I wanted to crop it to show only the LCD Display with some scaling and rotation. I tried MPlayer first but found it does not use good dithering in downsampling the video to 256 colors for GIFs resulting in poor splotchy images.
GoAniGiffy converts a set of alphabetically sorted image files (eg. video frames extracted as JPEGs)
into an animated GIF with the options to crop, scale, rotate & flip source images. Downsampling
and Scaling are done with high quality algorithms from the
github.com/disintegration/imaging library by
Grigory Dryapak and the Go Standard Library
Zipped executable binaries are available for Linux
& Windows in both 32 bit & 64 bit flavors. Download the zip appropriate to your OS and extract somewhere in your
system PATH. If you want to build from source
go get should fetch the imported libraries & build the utility
in your $GOPATH/bin.
1 go get github.com/srinathh/goanigiffy
GoAniGiffy is a command line utility to be used from the terminal - no GUIs for the present. Use GoAniGiffy with a command line of the form below. All parameters are optional and have sane default values.
1 goanigiffy -src="<file name pattern>" -<option>=<value> -<option>=<value>... -dest="<gif file name>"
-src = "<file name pattern>"
This specifies the input images using a file name pattern. You can use standard wildcards or a more complex pattern supported by the
path/filepathpackage in Go Language. GoAniGiffy will find matching files and sort them alphabetically before processing which makes it easy to use GoAniGiffy with numbered image frames extracted from videos. If you do not specfiy
-src, GoAniGiffy will use
"*.jpg"as the file pattern.
-dest="<gif file name>"
This specifies the file name and path for the output gif file. If you do not specifiy an output file, GoAniGiffy will by default create “movie.gif” in the current folder.
This specifies the delay between frames of the image in multiples of hundredths of a second. A value of 3 which is the default should theoritically give you 33 frames per second close to the default video speed.
If you want to crop the images, specify the left co-ordinate of the top-left corner of the rectangle you would like to crop here. The default value is 0
If you want to crop the images, specify the top co-ordinate of the top-left corner of the rectangle you would like to crop here. The default value is 0
If you want to crop the images, specify the width of the rectangle you would like to crop here. The default value is -1 which specifies the full image width.
If you want to crop the images, specify the height of the rectangle you would like to crop here. The default value is -1 which specifies the full image height.
Other Image Editing Options
If you want to scale the images, specify a scaling factor here in terms of decimals. For instance to make the animated GIF half the size as source images use -scale=0.5. The default value is 1.0 which specifies no scaling
-rotate=<0 or 90 or 180 or 270>
If you want the images to be rotated, specify the rotation angle in degrees here. Arbitrary rotations are not supported and you can only use 90, 180 or 270. The default value is 0 which specifies no rotation
-flip=<"none" or "horizontal" or "vertical">
If you want the images to be flipped, specify “horizontal” or “vertical” here. The default value is “none” which specifies no flipping
By default GoAniGiffy will process the files and exit without any messages unless there is an error. Specifying -verbose will show in-process messages as the individual frames get processed
Extracting Frames from Video
If you want to convert a video to an animated GIF, you first need to extract frames. I use MPlayer
with a command line like below to extract JPEG frames. The
-ss 6 -endpos 8 options specify extraction between the 6th and 8th seconds
1 mplayer -vo jpeg:quality=80 -nosound -ss 6 -endpos 8 vid.mp4
This command line creates a movie.gif from the images in the sample folder of the source repository.
1 goanigiffy -src="sample/*.jpg" -dest="sample/movie.gif" -cropleft=100 -croptop=280 -cropwidth=550 -cropheight=351 -scale=0.5 -rotate=270 -verbose
GoAniGiffy code is licensed under the Apache v2.0 license. All other media files & documentation in the repository is licened under Creative Commons Attribution-ShareAlike 4.0 International License.