Found this fpwritegif unit in the internet:
https://www.gocher.me/FPWriteGIF ; it does not support animated gifs, but maybe this is enough for you.
In order to use this unit you must register the new writer. I don't know how to hook into the existing TGifImage - but this is not necessary: simply create a new gif image class inherited from TGifImage, and this new class will use this writer unit. Put the following code into a separate unit, or put it to the top of the unit in which you want to write a gif image:
uses
..., graphics, fpimage, fpwritegif;
type
TMyGifImage = class(TGifImage)
protected
class function GetWriterClass: TFPCustomImageWriterClass; override;
end;
class function TMyGifImage.GetWriterClass: TFPCustomImageWriterClass;
begin
Result := TFPWriterGIF;
end;
In the initialization section of this unit register the new image class:
....
initialization
TPicture.RegisterFileFormat('.gif', 'gif', TMyGifImage);
Simply check the attached demo.
The gif writer unit seems to have an issue with memory management because the demo crashes in the local ClearMappings procedure - knowing that this could create a memory leak I simply bypassed the contents of this procedure, just to get a working example; but you are warned.