Exporting PSD to GIF is a common handoff for web graphics, email assets, and lightweight animations. With Aspose.PSD for .NET, you can convert a PSD to a static GIF in one call, and when a PSD contains an animation timeline, you can export an animated GIF directly from that timeline.
This article shows both scenarios with complete, inline code.
Prerequisites
- .NET 6 or later (or .NET Framework 4.6.2+)
- NuGet package:
Aspose.PSD
dotnet add package Aspose.PSD
Convert PSD to static GIF
Use Image.Load
to open the PSD, cast to PsdImage
, and save with GifOptions
. This flattens the PSD into a single-frame GIF.
// File: Program.cs
using System;
using System.IO;
using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.ImageOptions;
class Program
{
static void Main()
{
var inputPsd = "input.psd";
var outputGif = "output-static.gif";
if (!File.Exists(inputPsd))
{
Console.WriteLine("Input PSD not found.");
return;
}
using (var psd = (PsdImage)Image.Load(inputPsd))
{
// Export as a single-frame GIF
var gifOptions = new GifOptions();
psd.Save(outputGif, gifOptions);
}
Console.WriteLine("Saved: " + Path.GetFullPath(outputGif));
}
}
Notes
- Static export does not require a timeline in the PSD.
- The GIF palette is generated automatically. If you need a different file size or appearance, optimize the source artwork (flatten, simplify colors) before export.
Convert timeline-based PSD to animated GIF
If your PSD contains an animation timeline, you can export it as an animated GIF using the timeline API. This preserves frame order and frame delays stored in the PSD.
// File: Program.cs
using System;
using System.IO;
using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.ImageOptions;
class Program
{
static void Main()
{
var inputPsd = "animated.psd";
var outputAgif = "output-animated.gif";
if (!File.Exists(inputPsd))
{
Console.WriteLine("Input PSD not found.");
return;
}
using (var psd = (PsdImage)Image.Load(inputPsd))
{
if (psd.Timeline != null)
{
// Export PSD timeline as animated GIF
var gifOptions = new GifOptions();
psd.Timeline.Save(outputAgif, gifOptions);
Console.WriteLine("Saved animated GIF: " + Path.GetFullPath(outputAgif));
}
else
{
// Fallback to static export if the PSD has no timeline
var gifOptions = new GifOptions();
psd.Save(outputAgif, gifOptions);
Console.WriteLine("PSD has no timeline. Saved static GIF: " + Path.GetFullPath(outputAgif));
}
}
}
}
Notes
- This path respects frame order and per-frame delays defined in the PSD timeline.
- If your PSD does not have timeline data, the code falls back to a single-frame GIF.
Optional batch conversion
The following utility converts every PSD in a folder to GIF. Animated PSDs export via timeline when available, others export as static GIFs.
// File: BatchPsdToGif.cs
using System;
using System.IO;
using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.ImageOptions;
public static class BatchPsdToGif
{
public static void Run(string inputDir, string outputDir)
{
Directory.CreateDirectory(outputDir);
var psdFiles = Directory.GetFiles(inputDir, "*.psd", SearchOption.AllDirectories);
foreach (var psdPath in psdFiles)
{
var rel = Path.GetRelativePath(inputDir, psdPath);
var outFn = Path.ChangeExtension(rel, ".gif");
var outFp = Path.Combine(outputDir, outFn);
Directory.CreateDirectory(Path.GetDirectoryName(outFp) ?? outputDir);
try
{
using var psd = (PsdImage)Image.Load(psdPath);
var gifOptions = new GifOptions();
if (psd.Timeline != null)
{
psd.Timeline.Save(outFp, gifOptions);
}
else
{
psd.Save(outFp, gifOptions);
}
Console.WriteLine($"OK {rel} -> {outFn}");
}
catch (Exception ex)
{
Console.WriteLine($"ERR {rel}: {ex.Message}");
}
}
}
}
Call it from Main
:
// inside Main
// BatchPsdToGif.Run(@"C:\in-psd", @"C:\out-gif");
Best practices
- Color limits: GIF uses an indexed palette with up to 256 colors per frame. For complex artwork, consider simplifying layers or colors in the PSD for better dither and smaller files.
- Transparency: GIF supports 1-bit transparency. If you need full alpha, use PNG for static images and APNG for animation in compatible environments.
- File size: Animated GIFs can be large. Reduce frame count, frame size, or artwork detail to keep sizes practical.
- Verification: Always preview output in target environments to confirm timing, looping, and palette behavior.
With these patterns, you can automate both static and animated PSD to GIF exports inside your .NET workflows.