GIF format was introduced in 1987. It is widely used on Websites because it is the simplest way to implement the animations with a very small size. It is supported by all the browsers. Compare with the flash, it doesn’t need any plugin to play the animation in the web browser and it is very small in size.
GIF has two format, GIF87a and GIF89a. GIF87a is the original version of GIF format and GIF89a is the enhanced version, which supports for animation delays, transparent background and storage of application-specific metadata. By looking at the first six bytes of the GIF file, we can recognize the two versions by ASCII code, “GIF87a” and “GIF89a” respectively.
Playing GIF format is a very interesting job. Today I will show you how to change color of a GIF file. To replace the color of GIF files, we need to find out the color code first. Here is GIF animation which I am downloading from the internet. I downloaded it several months ago, so I forgot the original location.
GIF format maintains a global color tables and all color codes are represented inside. To get the color tables, we can download ImageMagick to help us solve the problems. After we installed ImageMagick, we can use follow command to find out the GIF color tables:
identify -verbose aa.gif | more
Colors in this color table are all used by this GIF animation. For example, we want to change the purple light ball to red light ball. First, let’s find out the color code of purple. This step can be quite tedious. We need to try all color codes in the Paint software to find out which one represents the purple color. Here, I find out the right color code is #7008E0. The second step is to type following command line to replace this color with our desired color, for example, #EE084F.
convert aa.gif -alpha set -channel RGBA -fill srgb(238,8,79) -opaque srgb(112,8,224) bb.gif
Here is the result:
Now, let’s change the purple color of GIF to yellow. Here is the commane line:
convert aa.gif -alpha set -channel RGBA -fill srgb(255,255,0) -opaque srgb(112,8,224) cc.gif
Here is the result:
In the future post, I will show you:
- How to convert GIF animation to Sprite Sheet
- How to play Sprite Sheet in Flash
- How to paly Sprite Sheet in HTML5