apng

package module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 11 Imported by: 1

README

GoDoc

apng

Fast APNG encoding with concurrent frame encoding.

Installation

go get github.com/setanarut/apng

20 frames animation encoding benchmark

Image Size kettek setanarut
125x125 173 ms 43 ms
250x250 655 ms 153 ms
500x500 2542 ms 565 ms
1000x1000 10174 ms 2213 ms
2000x2000 40745 ms 8831 ms
bench

Example

package main

import (
	"image"
	"image/color"
	"math/rand/v2"

	"github.com/setanarut/apng"
)

func main() {
	frames := make([]image.Image, 8)
	for i := range 8 {
		frames[i] = generateNoiseImage(600, 200)
	}
	apng.Save("out.png", frames, 7)
}

func generateNoiseImage(width, height int) *image.RGBA {
	img := image.NewRGBA(image.Rect(0, 0, width, height))
	for y := range height {
		for x := range width {
			col := noisePalette[rand.IntN(4)]
			img.SetRGBA(x, y, col)
		}
	}
	return img
}

var noisePalette = []color.RGBA{
	{R: 0, G: 0, B: 0, A: 255},   // Black
	{R: 255, G: 0, B: 0, A: 255}, // Red
	{R: 0, G: 255, B: 0, A: 255}, // Green
	{R: 0, G: 0, B: 255, A: 255}, // Blue
}

out

Documentation

Overview

apng is Animated PNG (APNG) encoder

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func APNGBytes added in v1.0.1

func APNGBytes(images []image.Image, delay uint16) []byte

APNGBytes encodes a slice of images into an APNG byte stream with a consistent delay per frame.

Images obtained via image.SubImage() are not supported, If an image is a sub-image, copy it into a new image before encoding.

The successive delay times, one per frame, in 100ths of a second (centiseconds).

func EncodeAll

func EncodeAll(w io.Writer, a *APNG) error

EncodeAll encodes the entire APNG struct to the io.Writer, validating input constraints.

Images obtained via SubImage() are not supported, If an image is a sub-image, copy it into a new image before encoding.

func Save added in v1.0.1

func Save(filePath string, images []image.Image, delay uint16)

Save writes an APNG file with the given images and uniform frame delay.

Images obtained via image.SubImage() are not supported, If an image is a sub-image, copy it into a new image before encoding.

The successive delay times, one per frame, in 100ths of a second (centiseconds).

Types

type APNG

type APNG struct {
	// The successive images.
	//
	// Images obtained via SubImage() are not supported, If an image is a sub-image, copy it into a new image before encoding.
	Images []image.Image
	// The successive delay times, one per frame, in 100ths of a second (centiseconds).
	Delays    []uint16
	Disposals []byte // The successive disposal methods, one per frame.
	LoopCount uint32 // The loop count. 0 indicates infinite looping.
	Config    image.Config
}

APNG encapsulates animated PNG frames, their delays, disposal methods, loop count, and global configuration.

Directories

Path Synopsis
_examples
write command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL