Pegasus now supports displaying and playing animated GIF files. When you load an animated GIF, the application automatically detects the animation and displays playback controls.
- When a GIF file is loaded, the application automatically detects if it contains multiple frames (animated)
- Static GIFs (single frame) are displayed normally without playback controls
- Animated GIFs show playback controls below the image
The GIF playback controls appear automatically for animated GIFs and include:
-
Play/Pause Button (▶/⏸)
- Click to play or pause the animation
- Animation plays automatically when first loaded
- Shows ▶ when paused, ⏸ when playing
-
Stop Button (■)
- Stops playback and returns to the first frame
- Useful for resetting the animation
-
Frame Counter
- Displays current frame / total frames (e.g., "1/316")
- Updates in real-time as animation plays
- Auto-play: Animated GIFs start playing automatically when loaded
- Frame timing: Each frame respects its original delay timing from the GIF metadata
- Looping: Supports infinite looping (most GIFs) and limited loops
- Pause on operations: Animation automatically pauses when you perform operations like:
- Undo/Redo (Ctrl+Z / Ctrl+Y)
- Crop, resize, filter, rotate
- Format conversion
- Uses Sharp library's native GIF animation support
- Extracts individual frames on-demand for smooth playback
- Respects original frame delays (in milliseconds)
- Memory efficient - doesn't pre-load all frames
-
Via File Menu:
- Click File → Open
- Select a GIF file
- If animated, controls appear automatically
-
Via Drag & Drop:
- Drag a GIF file into the application
- Drop it on the canvas area
- Controls appear if the GIF is animated
-
Via Paste:
- Copy a GIF file to clipboard
- Press Ctrl+V in the application
- Controls appear if the GIF is animated
- Play: Click the ▶ button or it plays automatically
- Pause: Click the ⏸ button to pause
- Stop: Click the ■ button to stop and reset to first frame
- Frame info: Watch the frame counter to see current position
- Editing: You can apply filters, resize, crop, etc. to the current displayed frame
- Converting: When you convert to another format, animation is removed (uses current frame)
- Saving: Saves the original animated GIF if extension stays as .gif
- Format Change: Changing extension to non-GIF formats will save the current frame only
// The application automatically detects animation
// You just open the file normally
await layer.openImage('path/to/animated.gif');
// Controls appear automatically if animatedif (layer.isAnimatedGif()) {
console.log('This is an animated GIF with', layer.gifMetadata.pages, 'frames');
}// Play
layer.playGifAnimation();
// Pause
layer.pauseGifAnimation();
// Stop (reset to frame 0)
layer.stopGifPlayback();✅ Supported:
- Multiple frames (animated GIFs)
- Per-frame delay timing
- Infinite looping (loop = 0)
- Limited looping (loop = N)
- Variable frame delays
- Transparent backgrounds
- Palette-based GIFs
❌ Not Supported:
- Editing individual frames
- Creating new animated GIFs from scratch
- Adding/removing frames
- Modifying frame delays
- Frame extraction is on-demand (not pre-loaded)
- Smooth playback for most GIFs
- Large GIFs (many frames or high resolution) may have slight delays during frame extraction
- Memory usage is efficient as frames are not kept in memory
- Check if it's a static GIF (only 1 frame)
- Verify the file is not corrupted
- Try re-opening the file
- This is normal for GIFs with very short frame delays (<50ms)
- Try a different GIF to verify
- Check system resources (CPU usage)
- Ensure the GIF has multiple frames
- Check the extension is
.gif - Try reloading the file
The GIF animation support is implemented in:
-
ImageLoader (
imgkit/processing/image_loader.js)- Detects animated GIFs via metadata (pages > 1)
- Extracts individual frames using Sharp's page option
- Returns GIF metadata (pages, delay, loop)
-
ImageLayer (
imgkit/core/image_layer.js)- Manages animation state and playback
- Creates and controls UI elements (buttons, counter)
- Schedules frame display based on delays
- Handles pause/play/stop logic
-
Sharp Library
- Provides native GIF reading with animation support
- Extracts frames via
sharp(buffer, { page: N }) - Returns metadata with pages, delay, loop info