Submitted by mikesven on Tue, 04/10/2012 - 18:37
A little while ago a friend of mine had asked me to help him out with an idea for a new work flow he was testing. He was looking to be able to work his photoshop/illustrator magic and export everything as a .gif file. From there he wanted to decompile the .gif file into individual frames that he could then bring into after effects or flash and create a short animatic. After hearing the idea, this seemed like a perfect spot to use Image Magick. For those of you who don't know, Image Magick is an open source software suit to compose, edit or convert bitmap images. Now once you have installed Image Magick this can simply be done though the command line using the line below:
convert $RAW_FILE_LOC -coalesce $OUTPUT_DIR/frame\_%04d.png
This will take a .gif image ($RAW_FILE_LOC) and output its frames to a given directory ($OUTPUT_DIR) with a numbered file name containing up to 4 digits. This is fine and dandy, but I wanted to make it easier for my friend to decomplie his images with out having to go though an install process and the command line. NikGIF was born. Using a little bit of jQuery and PHP i put together a small front end that interacts with the server and returns a .tar.gz with all of your extracted images. At the heart of the application lies a slight expanded bash script:
#!/bin/bash DIR_NAME=$1 RAW_FILE_LOC=$2 mkdir finished-packages/$DIR_NAME convert $RAW_FILE_LOC -coalesce finished-packages/$DIR_NAME/frame\_%04d.png cd finished-packages tar -czf $DIR_NAME.tar.gz $DIR_NAME rm -rf $DIR_NAME rm -rf $RAW_FILE_LOC echo finished-packages/$DIR_NAME.tar.gz
The above script does the following:
- create a new directory with a given name to hold the individual frames
- convert the .gif image from its uploaded location into individual frames in the above mentioned directory
- create a .tar.gz of the directory with all of the extracted frames
- remove the directory from the file system
- remove the uploaded image from the file system
- return the location of the .tar.gz file for the user
Pretty simple, and a great way to get the job done. One thing I might look into is a cron task to remove the .tar.gz files every so often to free up server space. If you are interested in checking out the front end and PHP code for NikGIF it can be found on github. Feel free to fork it and use it, I would love to hear about any improvements you have made!
- mikesven's blog
- Log in to post comments