GIF-Builder
Build Bitmap Frames to Animated GIF File, or export frames from a GIF file.
- Active · last change 8-26-2026
- ★ 1 on GitHub
README
:computer: GIF-Builder:




TGIFImage is a full TGraphic implementation of the GIF graphics format.
It reads, writes and displays animated GIFs and can convert to and from TBitmap (i.e. the BMP format) and any other TGraphic derived format (e.g TJPEGImage, TIcon and TMetaFile).TGIFImage can either be used stand-alone or as part of Delphi’s extensible TImage/TPicture/TGraphic framework. When used in connection with the TImage component, TGIFImage registers itself with the TPicture class, giving you instant support for the GIF format throughout Delphi. After installing TGIFImage, you will be able to load, save and display GIFs without any additional code!
TGIFImage has full support for animated GIF and is the only solution that can display animated GIFs in the TImage component. TGIFImage implements the complete GIF87a and GIF89a specification as well as all common GIF extensions:
- Transparency and interlacing
- Local- and global palettes of 2,4,8,16,32,64,128 & 256 colors
- Palette optimization
- Delay and Loops for animations
- Text- and comment extension
- Application extensions
- Disposal to previous frame and background image And much more…
Support for new Application Extension types can be added by the developer without modification to the TGIFImage source by registering the format at run-time with TGIFImage. To demonstrate its use, TGIFImage comes with several sample applications: The “GIF Explorer” that can be used to view GIF files and examine their structure, a “simple” web-counter that demonstrates how to use TGIFImage with the Delphi CGI, ISAPI and NSAPI components together, an animated button component and an AVI to GIF and GIF to AVI converter just to mention a few of them.
:speech_balloon: Frame Order
Although GIF was not designed as an animation medium, its ability to store multiple images in one file naturally suggested using the format to store the frames of an animation sequence. To facilitate displaying animations, the GIF89a spec added the Graphic Control Extension (GCE), which allows the images (frames) in the file to be painted with time delays, forming a video clip. Each frame in an animation GIF is introduced by its own GCE specifying the time delay to wait after the frame is drawn.
Once the frames have been loaded, the playback order can be determined using the list by dragging the path names up or down.
This is very useful when loading numeric filenames that a list box does not always list in numeric order.
:speech_balloon: Export frames restrictions
To export the frames of a GIF file, each frame must be extracted individually. Generally, these images are saved in GIF format, but they can also be exported to other formats.
Formats : gif; bmp; jpg; png; ico; tif; emf; wmf;
However, there are limitations here. The project includes an older GIF library that is unable to export all GIF frames at the optimal image size.
Naturally, a more powerful GIF library exists, but it is a licensed, paid product. Anyone wishing to make full use of this feature can purchase and integrate that library.
:speech_balloon: Watermark
If you want to protect your own GIF animations, you can embed a watermark into the animation here. When activated, the specified text is rendered into all frames at your chosen position.
Example:
:speech_balloon: Converting bitmap to a GIF file
procedure ConvertBMP2GIF;
var
bmp: TBitmap;
gif: TGIFImage;
begin
gif := TGifImage.Create;
try
bmp := TBitmap.Create;
try
bmp.LoadFromFile('MyBitmap.BMP');
gif.Assign(bmp);
finally
bmp.Free;
end;
gif.SaveToFile('MyBitmap.GIF');
finally
gif.Free;
end;
end;:speech_balloon: How do I make a transparent GIF?
One color entry in a single GIF or PNG image's palette can be defined as "transparent" rather than an actual color. This means that when the decoder encounters a pixel with this value, it is rendered in the background color of the part of the screen where the image is placed, also if this varies pixel-by-pixel as in the case of a background image.
Try something like this:
var
GIF: TGIFImage;
Ext: TGIFGraphicControlExtension;
begin
GIF := TGIFImage.Create;
try
// Convert bitmap to GIF
GIF.Assign(Bitmap);
// Create an extension to set the transparency flag
Ext := TGIFGraphicControlExtension.Create(GIF.Images[0]);
Ext.Transparent := True;
// Set transparent color to lower left pixel color
Ext.TransparentColorIndex := GIF.Images[0].Pixels[0, GIF.Height-1];
// Do something with the GIF here...
...
finally
GIF.Free;
end;
end;Portable Network Graphics (PNG) was designed as a replacement for GIF to avoid infringement of Unisys' patent on the LZW compression technique. PNG offers better compression and more features than GIF, animation being the only significant exception. PNG is more suitable than GIF in instances where true-color imaging and alpha transparency are required.
Many other freeware GIF libraries exists, so you might wonder why we need another one… The need for TGIFImage arose when I was writing a CGI application that needed to create large GIF images on-the-fly. After having tested a number of freeware libraries I concluded that they weren’t quite fit for the job with regard to performance and GIF compliance. Some of the DLL based implementations were OK, but Delphi integration were missing. So after reading through the GIF specifications and several articles on LZW compression, I decided that it couldn’t be to hard to whip something useful together.
The name TGIFImage might be a bit unfortunate as almost every known Delphi implementation of the GIF format is called TGIFImage, but it’s the most logical name for the gizmo and it shouldn’t be a problem once I have made the “competing” implementations obsolete :-)
TGIFImage has been tested with several thousand GIF files, so I’m fairly confident that it will handle whatever you throw at it. If you find a valid GIF file that cannot be handled correctly by TGIFImage, please mail it to me with a description of the problem enter a QC report, and I’ll give you your money back :-).
:speech_balloon: Compression
In 1977 and 1978, Jacob Ziv and Abraham Lempel published a pair of papers on a new class of lossless data-compression algorithms, now collectively referred to as LZ77 and LZ78. In 1983, Terry Welch developed a fast variant of LZ78 which was named Lempel–Ziv–Welch (LZW).
Welch filed a patent application for the LZW method in June 1983. The resulting patent, US4558302, granted in December 1985, was assigned to Sperry Corporation who subsequently merged with Burroughs Corporation in 1986 and formed Unisys.Further patents were obtained in the United Kingdom, France, Germany, Italy, Japan and Canada.
:speech_balloon: Features
So what can TGIFImage do and how does it differentiate itself from some of the other implementations?
- Full source included.
- Derived from TGraphic.
- Supports all palette sizes.
- Fast decode and encode.
- Based on known solid algorithms.
- Handles unknown extensions gracefully.
- Tolerant. Loads and displays corrupt GIFs.
- Easy to extend.
- Reduces file size by minimizing palette size.
- Does not use idle-looping.
- Integrates with TImage, TOpenPictureDialog and TSavePictureDialog.
- Dithers to the Netscape web-safe palette on 256 color systems.
- Displays animations in TImage.
- Non-destructive GIF optimizer reduces GIF file size.
- Context sensitive on-line help.
- Automatic color reduction of bitmaps with more than 256 colors using color quantization and 6 different dithering methods (e.g. Floyd Steinberg).
:speech_balloon: Optimize Features
- Merge
- Crop
- Clean Up
- Tranzparent
- Stretch
- Color Mapping
- Remove Comments
- Reduce Colors
- Compression Mode
:speech_balloon: Color Options
- Netscape
- Monochrome
- Gray Scale
- Windows Gray
- Windows 256 (This is the actual color setting)
- Windows20
- Quantize
- Quantize Windows
- Palette
:speech_balloon: Dithering Modes
- FloydSteinberg
- Nearest
- Sierra
- Stucki
- Burkes
- SteveArch
:speech_balloon: Current Status
In February 2007 I donated TGIFImage to CodeGear with the purpose of adding in-the-box GIF support to the VCL, starting with Delphi 2007.
Besides giving me motivation to work on TGIFImage again, the transfer of ownership also gave me an opportunity to pull TGIFImage out the limbo it had been in and secure future development.
Where to get TGIFImage? The official TGIFImage version 2.2 release is available from a lot of places on the net. However since the official release hasn’t been maintained since I distributed it in May 1999, I strongly suggest you use one of the following releases instead.
Finn Tolderlund’s Version 2.2.* Finn has been maintaining TGIFImage on his own since my former web site disappeared. His version is based on the official TGIFImage version 2.2 release. For an updated TGIFImage version 2.2, supporting Delphi 5-2007, please go to Finn Tolderlund’s web site. In addition to the updated sources, I recommend you also get the original version 2.2 installation kit (also available from Finn’s site), since that contains the documentation and all the demos.
CodeGear’s Version 3.0 Since Delphi 2007 TGIFImage version 3.0 is included with all revisions of Delphi. Please note that this version does not support earlier versions of Delphi.
Version 3.0 was written by me and is a fork of version 2.3, a version that was never widely released. By fork I mean that it isn’t meant as a progressive continuation of the old TGIFImage. Backward compatibility was not a design requirement of the new TGIFImage, so I took the opportunity to remedy some of the things that I felt was wrong in the old version and some of these things could only be done without consideration for backward compatibility. Those that need backward compatibility should use Finn’s version.
Version 3 differs from version 2.2 in the following ways:
- The interface has changed, but it is drop-in compatible with earlier version if one doesn’t use the TGIFImage class directly. E.g. if you just use TImage to display GIFs, then you should be fine.
- Many classes and properties have been renamed for better consistency. E.g. TGIFSubImage is now named TGIFFrame.
- The rendering engine has been completely rewritten from scratch. The rendering of animated GIFs is now handled with a timer and windows messages instead of a thread. The primary implication of this change is that the rendering is now done synchronously instead of asynchronously. Not as sexy but more safe.
- Animation is disabled by default. This was done for consistency with other (actually all other) TGraphic class (e.g. TBitmap, TIcon, etc). I judged that the average user wouldn’t want (or expect) animated content in TImage as no other TGraphic descendants support it. Please see the FAQ for a description of how to enable animation.
- Support for earlier versions of Delphi has been removed. Version 3 has only been tested on Delphi 2007 and later; It may or may not work with Delphi 2005 or Delphi 2006.
- The tiling feature has been removed from the TImage rendering. The low level rendering engine still supports it though.
- It is no longer necessary to edit the source to configure options. Most of the options that were previously configurable with conditional defines (i.e. compile time options) are now controlled with variables (i.e. run time options).
[Update: 03-apr-2008] The first of the demos is now available: Animation Demo for TGIFImage v3.

