Merge GIF to GIF Using C#

GIF files have a small file size, which makes them ideal for website usage for logos, line art and simple cartoons. It uploads quickly since these files are usually low resolution. In some cases, you may need to combine GIF images and save them as one file. With Aspose.SVG for .NET API, you can merge GIF to GIF programmatically. Powerful C# API helps you to combine GIF files quickly and in high quality!


C# code example to merge GIF to GIF

Combine multiple GIF files and save the result as a single GIF file easily! Merging images can be done with a few lines of code:


Merge GIF to GIF - C#

// Images to merge 
var images = new string[] { @"image1.gif", "image2.gif" };
// Initialize a new instance of SVGDocument
using (var document = new SVGDocument())
{
    // Declare an image function
    SVGImageElement CreateThumbnail(string imagePath, int width, int height)
    {
        var image = (SVGImageElement)document.CreateElementNS("http://www.w3.org/2000/svg", "image");
        image.Href.BaseVal = imagePath;
        image.Width.BaseVal.Value = width;
        image.Height.BaseVal.Value = height;
        return image;
    }
    // Set a thumbnail size
    const int thumbnailWidth = 200;
    const int thumbnailHeight = 200;
    const int thumbnailMargin = 10;
    // Create thumbnails merging loop
    for (var i = 0; i < images.Length; i++)
    {
        // Create a thumbnail
        var thumbnail = CreateThumbnail(images[i], thumbnailWidth, thumbnailHeight);
        // Define coordinates 
        thumbnail.X.BaseVal.Value = 0;
        thumbnail.Y.BaseVal.Value = (thumbnailHeight + thumbnailMargin) * i;
        // Append the thumbnail to the document
        document.DocumentElement.AppendChild(thumbnail);
    }
    // Define saving options
    var options = new ImageRenderingOptions
    {
        Format = ImageFormat.Gif,
        PageSetup =
        {
            Sizing = SizingType.FitContent
        }
    };    
    // Render document 
    document.RenderTo(new ImageDevice(options, "merged.gif"));
}



Steps to Merge GIF to GIF using C#

  1. Define GIF images to merge.
  2. Initialize a new instance of the SVGDocument class.
  3. Declare an image function. You should use the CreateElementNS(namespaceURI, qualifiedName) method of the SVGDocument class to create an image instance. The namespaceURI sets the reference to W3C SVG specification. The qualifiedName must contain the string tag name of the image element.
  4. Call the image function to create a thumbnail object.
  5. To add thumbnails to the document, use AppendChild() method.
  6. Use one of the ImageRenderingOptions() constructor to initialize a new instance of the ImageRenderingOptions class. You can customize the rendering process by specifying the page size, image format, etc. PNG is used as the default image format.
  7. Create an instans of ImageDevice using the ImageDevice() constructor.
  8. Call the RenderTo(device) method to send the current document to the output rendering device.
  9. Multiple GIF images will be saved into one GIF file on the specified path.

A high-speed C# library allows .NET developers to merge GIF files into one image quickly and efficiently. The Aspose.Svg.Rendering.Image namespace provides specific device classes as well as a few rendering options classes responsible for rendering to raster formats: JPEG, PNG, BMP, GIF, and TIFF. Please visit our Documentation to learn more about using Aspose.SVG API functions.


Online Image Merger

Aspose.SVG offers a free online Image Merger App that combines multiple images into a single file. You can choose a kind of Image Merger for different source files such as SVG, JPG, PNG, BMP, ICO, GIF, or TIFF, and save the result to one of the following output formats: JPG, PNG or SVG. Our application is multifunctional. You can create image collages, edit and manipulate images before merging. Image Merger allows you to freely add images, rotate, scale, add backgrounds, filters and move each image until you are happy with the end result of your design.


FAQ

1. How can I merge several GIF into GIF?

You will sometimes need to merge two or more GIF images in your daily work. Aspose.SVG allows you to merge GIF into other formats in any way - online or programmatically. Online Image Combiner helps you combine images quickly and with high quality. C# API provides the Renderer class for rendering and merging GIF files programmatically.

2. In what formats can I save the result of GIF merge via C#?

You can save the GIF merge result in the most common formats such as JPG, PNG, BMP, GIF, TIFF, etc.

3. Why do I need to merge multiple GIF files?

There are many reasons why you want to merge several images into one. For example, you want to make a collage or create a new drawing based on several GIF images. You may need to merge GIF and save the result as GIF for easy storage or mailing.

Get Started with .NET SVG API

If you are interested in developing scalable vector graphics and their application, install our flexible, high-speed Aspose.SVG for .NET API with a powerful set of interfaces for C# and other .NET programming languages.
Install from command line as nuget install Aspose.SVG or via Package Manager Console of Visual Studio with Install-Package Aspose.SVG. Alternatively, get the offline MSI installer or DLLs in a ZIP file from downloads. Aspose.SVG for .NET API is a standalone library and does not depend on any software for SVG document processing.
For more details about C# library installation and system requirements, please refer to Aspose.SVG Documentation.

Other Supported Mergers

You can merge Images into other file formats:

JPG to JPG (JPEG Image)
JPG to PNG (Portable Network Graphics)
JPG to BMP (Bitmap Image)
JPG to GIF (Graphical Interchange Format)
JPG to TIFF (Tagged Image Format)
PNG TO PNG (Portable Network Graphics)
PNG to JPG (JPEG Image)
PNG to BMP (Bitmap Image)
PNG to GIF (Graphical Interchange Format)
PNG to TIFF (Tagged Image Format)
GIF to JPG (JPEG Image)
GIF to PNG (Portable Network Graphics)
SVG TO PDF (Portable Document Format)
SVG TO XPS (XML Paper Specifications)
SVG TO BMP (Bitmap Image)
SVG TO IMAGE (Image formats)
SVG TO JPEG (JPEG Image)
SVG TO GIF (Graphical Interchange Format)
SVG to PNG (Portable Network Graphics)
SVG TO TIFF (Tagged Image Format)