https://github.com/sapphi-red/midec
Pure go multi-image detector. cf. Animated GIF, APNG, Animated WebP, Animated HEIF/AVIF.
https://github.com/sapphi-red/midec
apng avif golang heif png webp
Last synced: 2 months ago
JSON representation
Pure go multi-image detector. cf. Animated GIF, APNG, Animated WebP, Animated HEIF/AVIF.
- Host: GitHub
- URL: https://github.com/sapphi-red/midec
- Owner: sapphi-red
- License: mit
- Created: 2021-04-04T19:55:55.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2021-05-22T12:33:41.000Z (almost 4 years ago)
- Last Synced: 2025-01-25T05:11:40.710Z (4 months ago)
- Topics: apng, avif, golang, heif, png, webp
- Language: Go
- Homepage:
- Size: 260 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# midec [](https://pkg.go.dev/github.com/sapphi-red/midec) [](https://github.com/sapphi-red/midec/actions/workflows/main.yaml) [](https://codecov.io/gh/sapphi-red/midec)
Pure go **m**ulti-**i**mage **de**te**c**tor.
cf. Animated GIF, APNG, Animated WebP, Animated HEIF / AVIF.Checks whether the image is a multi-image(animated image).
## Usage
```go
package mainimport (
"fmt"
"os""github.com/sapphi-red/midec"
_ "github.com/sapphi-red/midec/gif" // import this to detect Animated GIF
// _ "github.com/sapphi-red/midec/png" // import this to detect APNG
// _ "github.com/sapphi-red/midec/webp" // import this to detect Animated WebP
// _ "github.com/sapphi-red/midec/isobmff" // import this to detect Animated HEIF / AVIF
)func main() {
fp, err := os.Open("test.gif")
if err != nil {
panic(err)
}isAnimated := midec.IsAnimated(fp)
fmt.Println(isAnimated)
}
```## Extension
To add support for other formats, use `midec.RegisterFormat`.
This function is very similar to [`image.RegisterFormat`](https://golang.org/pkg/image/#RegisterFormat).```go
func init() {
midec.RegisterFormat("gif", gifHeader, isAnimated)
}
```## Benchmarks
Comparison with using `image/gif` package's `gif.decodeAll`. See code for [`bench_test.go`](https://github.com/sapphi-red/midec/blob/main/bench_test.go).
```text
goos: windows
goarch: amd64
pkg: github.com/sapphi-red/midec
cpu: AMD Ryzen 7 3700X 8-Core Processor
BenchmarkGIF_ImageGIF-16 2581 443108 ns/op 497567 B/op 1435 allocs/op
BenchmarkGIF_Midec-16 157585 7568 ns/op 5008 B/op 36 allocs/op
BenchmarkPNG_Midec-16 265256 4811 ns/op 5008 B/op 13 allocs/op
BenchmarkWebP_Midec-16 181000 6667 ns/op 5040 B/op 20 allocs/op
BenchmarkHEIFAVIF_Midec-16 188468 5967 ns/op 5136 B/op 44 allocs/op
PASS
ok github.com/sapphi-red/midec 23.147s
```