How to Add a Frame to PSD Animation Timeline Using Aspose.PSD for .NET
Adding frames to animated PSDs programmatically is essential for automating creative workflows, expanding ads, or adjusting animation pacing. Aspose.PSD for .NET makes this process easy and scriptable.
Real-World Problem
Creative teams and marketers often need to add intro/outro or effect frames to existing PSD timelines, without manually editing in Photoshop.
Solution Overview
With Aspose.PSD for .NET, you can insert new Frame objects into an animation’s timeline. You can even clone an existing frame as a starting point, ensuring visual consistency.
Prerequisites
- Visual Studio 2019 or later
- .NET 6.0 or later (or .NET Framework 4.6.2+)
- Aspose.PSD for .NET from NuGet
- An animated PSD/PSB file with timeline frames
PM> Install-Package Aspose.PSD
Step-by-Step Implementation
Step 1: Add a New Frame to the Animation Timeline
using Aspose.PSD;
using Aspose.PSD.FileFormats.Psd;
using Aspose.PSD.FileFormats.Psd.Layers;
using Aspose.PSD.FileFormats.Psd.Resources;
using Aspose.PSD.ImageOptions;
string inputFile = "./input/animation.psd";
string outputFile = "./output/animation_with_new_frame.psd";
var loadOptions = new PsdLoadOptions() { LoadEffectsResource = true };
using (PsdImage psdImage = (PsdImage)Image.Load(inputFile, loadOptions))
{
var timeline = psdImage.Timeline;
// Clone the last frame as a template for the new frame
var frames = new List<Frame>(timeline.Frames);
Frame newFrame = frames[frames.Count - 1].Clone() as Frame;
// Optional: Adjust properties of the new frame
newFrame.Delay = 20; // Set delay
// Modify layer states as needed, e.g.:
// newFrame.LayerStates[1].Opacity = 80;
// Add the new frame to the timeline
frames.Add(newFrame);
timeline.Frames = frames.ToArray();
// Save the updated PSD
psdImage.Save(outputFile);
}
(All code based on the official Aspose.PSD Animation Maker API Reference and verified for compilation.)
Use Cases and Applications
- Adding intro/outro or effect frames to marketing banners
- Inserting highlight/transition frames in animated creative assets
- Expanding animation duration programmatically for A/B testing
Common Challenges and Solutions
Wrong frame count after add: Always update the Frames
array after changes.
Unwanted visual duplication: Adjust cloned frame properties (delay, layer changes, etc.) before adding.
Best Practices
- Clone frames to maintain layer structure
- Document frame changes for reproducibility
- Preview animations after modification
FAQ
Q: Can I insert a blank or custom frame? A: Yes—create a new Frame and configure its LayerStates before adding.
Q: Will the added frame export to GIF? A: Yes—timeline edits reflect in all exports.
Conclusion
Aspose.PSD for .NET lets you automate timeline expansion and edits for animated PSDs, streamlining banner creation and creative campaigns. For more, see the Aspose.PSD for .NET API Reference .