How to merge GIF images using C#

GIF Merger .NET API

GroupDocs.Merger allows developers to combine multiple GIF documents in the preferred order and save them as a single file.

About GIF File Format

GIF, Graphics Interchange Format, is a raster file format designed for relatively basic images that appear mainly on the internet. Each file can support up to 8 bits per pixel and can contain 256 indexed colors. GIF files also allow images or frames to be combined, creating basic animations.

Download and Configure

Use the downloads section to download API DLLs or MSI installer or NuGet:

PM> Install-Package GroupDocs.Merger

Source GIF images

“Sample1.gif” “Sample2.gif” “Sample3.gif”

How to merge GIF files in horizontal mode

The following example demonstrates how to merge image files in horizontal mode with several lines of C# code:

  • Create an instance of Merger class and pass source image file path as a constructor parameter. You may specify absolute or relative file path as per your requirements.
  • Create an instance of ImageJoinOptions class and pass enum value of ImageJoinMode as a constructor parameter.
  • Add another image file to merge with Join method and pass instance of ImageJoinOptions class as a method parameter. Repeat this step for other image documents you want to merge.
  • Call Merger class Save method and specify the filename for the merged image file as parameter.
// Load the source image file
using (Merger merger = new Merger(@"c:\sample1.gif"))
{
    // Define image join options with horizontal join mode
    ImageJoinOptions joinOptions = new ImageJoinOptions(ImageJoinMode.Horizontal);
    // Add another image file to merge
    merger.Join(@"c:\sample2.gif", joinOptions);
    // Add next image file to merge
    merger.Join(@"c:\sample3.gif", joinOptions);
    // Merge image files and save result
    merger.Save(@"c:\merged.gif");
}

Result merged GIF image

“Merged.png”

Code Examples

Please find more use-cases and complete C# sources of our backend and frontend examples and try them for free!

Merge GIF Live Demo

GroupDocs.Merger for .NET provides an online GIF Merger App, which allows you to try it for free and check its quality and accuracy.