Skip to content

Commit a05aaec

Browse files
committed
init
0 parents  commit a05aaec

File tree

10 files changed

+503
-0
lines changed

10 files changed

+503
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Binaries for programs and plugins
2+
*.exe
3+
*.dll
4+
*.so
5+
*.dylib
6+
7+
# Test binary, build with `go test -c`
8+
*.test
9+
10+
# Output of the go coverage tool, specifically when used with LiteIDE
11+
*.out
12+
13+
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
14+
.glide/
15+
16+
.gvm
17+
vendor/

LICENSE.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Barış
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
22+
23+
---
24+
25+
The Go gopher mascot was designed by Renee French.
26+
The design is licensed under the [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/) license

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[![GoDoc](https://godoc.org/github.com/setanarut/apng?status.svg)](https://pkg.go.dev/github.com/setanarut/apng)
2+
3+
# apng
4+
apng is implementation of [APNG(Animated PNG)](https://developer.mozilla.org/en-US/docs/Mozilla/Tech/APNG) Encoder in Go.
5+
6+
![animated_gopher](_example/res/animated_gopher.png)
7+
8+
## Installation
9+
10+
```sh
11+
go get github.com/setanarut/apng
12+
```
13+
14+
## Usage
15+
See: [example.go](_example/example.go).

_example/main.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"image/png"
6+
"os"
7+
8+
"github.com/setanarut/apng"
9+
)
10+
11+
func main() {
12+
inPaths := []string{
13+
"res/gopher01.png",
14+
"res/gopher02.png",
15+
"res/gopher03.png",
16+
}
17+
outPath := "res/animated_gopher.png"
18+
19+
// Assemble output image.
20+
outApng := &apng.APNG{}
21+
for _, inPath := range inPaths {
22+
// Read image file.
23+
f, err := os.Open(inPath)
24+
if err != nil {
25+
fmt.Println(err)
26+
f.Close()
27+
return
28+
}
29+
inPng, err := png.Decode(f)
30+
if err != nil {
31+
fmt.Println(err)
32+
f.Close()
33+
return
34+
}
35+
f.Close()
36+
37+
// Append a frame(type: *image.Image). First frame used as the default image.
38+
outApng.Images = append(outApng.Images, inPng)
39+
40+
// Append a delay time(type: uint32) per frame in 10 milliseconds.
41+
// If it is 0, the decoder renders the next frame as quickly as possible.
42+
outApng.Delays = append(outApng.Delays, 0)
43+
}
44+
45+
// Encode images to APNG image.
46+
f, err := os.Create(outPath)
47+
if err != nil {
48+
fmt.Println(err)
49+
f.Close()
50+
51+
return
52+
}
53+
if err = apng.EncodeAll(f, outApng); err != nil {
54+
fmt.Println(err)
55+
f.Close()
56+
os.Remove(outPath)
57+
return
58+
}
59+
f.Close()
60+
}

_example/res/animated_gopher.png

63 KB
Loading

_example/res/gopher01.png

24.2 KB
Loading

_example/res/gopher02.png

22.5 KB
Loading

_example/res/gopher03.png

23.4 KB
Loading

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/setanarut/apng
2+
3+
go 1.24.1

0 commit comments

Comments
 (0)