https://github.com/setanarut/apng
APNG encoder in Go
https://github.com/setanarut/apng
Last synced: 12 months ago
JSON representation
APNG encoder in Go
- Host: GitHub
- URL: https://github.com/setanarut/apng
- Owner: setanarut
- License: other
- Created: 2025-03-31T14:09:33.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-31T14:48:52.000Z (over 1 year ago)
- Last Synced: 2025-03-31T15:50:56.410Z (over 1 year ago)
- Language: Go
- Size: 134 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://pkg.go.dev/github.com/setanarut/apng)
# apng
Fast APNG encoding with concurrent frame encoding.
## Installation
```sh
go get github.com/setanarut/apng
```
## 20 frames animation encoding benchmark
| Image Size | [kettek](https://github.com/kettek/apng) | [setanarut](https://github.com/setanarut/apng) |
| ---------- | ---------------------------------------- | ---------------------------------------------- |
| 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 |

## Example
```Go
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
}
```
