diff --git a/go.mod b/go.mod index 5767b70..6d5accf 100644 --- a/go.mod +++ b/go.mod @@ -6,6 +6,7 @@ require ( github.com/goccy/go-json v0.10.2 github.com/gofiber/fiber/v2 v2.52.4 github.com/gofiber/template/jet/v2 v2.1.9 + github.com/kettek/apng v0.0.0-20220823221153-ff692776a607 github.com/tidwall/gjson v1.17.1 golang.org/x/net v0.24.0 ) diff --git a/go.sum b/go.sum index 1d33cb0..4f7a6e1 100644 --- a/go.sum +++ b/go.sum @@ -18,6 +18,8 @@ github.com/gofiber/utils v1.1.0 h1:vdEBpn7AzIUJRhe+CiTOJdUcTg4Q9RK+pEa0KPbLdrM= github.com/gofiber/utils v1.1.0/go.mod h1:poZpsnhBykfnY1Mc0KeEa6mSHrS3dV0+oBWyeQmb2e0= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +github.com/kettek/apng v0.0.0-20220823221153-ff692776a607 h1:8tP9cdXzcGX2AvweVVG/lxbI7BSjWbNNUustwJ9dQVA= +github.com/kettek/apng v0.0.0-20220823221153-ff692776a607/go.mod h1:x78/VRQYKuCftMWS0uK5e+F5RJ7S4gSlESRWI0Prl6Q= github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= diff --git a/proto_apng/119477424_ugoira600x600.zip b/proto_apng/119477424_ugoira600x600.zip new file mode 100644 index 0000000..060f572 Binary files /dev/null and b/proto_apng/119477424_ugoira600x600.zip differ diff --git a/proto_apng/main.go b/proto_apng/main.go new file mode 100644 index 0000000..f9be088 --- /dev/null +++ b/proto_apng/main.go @@ -0,0 +1,61 @@ +package main + +import ( + "archive/zip" + "fmt" + "image" + "io" + "os" + + "github.com/kettek/apng" +) + +func main() { + filename := "119477424_ugoira600x600.zip" + f, err := os.Create("out.apng") + if err != nil { + panic(err) + } + err = zip2apng(filename, f, 1000, 1000) + if err != nil { + panic(err) + } +} + +// APNG spec: https://wiki.mozilla.org/APNG_Specification + +// each frame will be delayed (delayNumerator/delayDenominator) seconds +func zip2apng(filename string, w io.Writer, delayNumerator, delayDenominator uint16) error { + // Open a zip archive for reading. + r, err := zip.OpenReader(filename) + if err != nil { + return err + } + defer r.Close() + + img_apng := apng.APNG{} + + // Iterate through the files in the archive, + // printing some of their contents. + for _, f := range r.File { + fmt.Printf("Contents of %s:\n", f.Name) + rc, err := f.Open() + if err != nil { + return err + } + defer rc.Close() + img, img_format, err := image.Decode(rc) + _ = img_format + if err != nil { + return err + } + frame := apng.Frame{ + Image: img, + DelayNumerator: delayNumerator, + DelayDenominator: delayDenominator, + } + img_apng.Frames = append(img_apng.Frames, frame) + } + + return apng.Encode(w, img_apng) +} diff --git a/proto_apng/out.apng b/proto_apng/out.apng new file mode 100644 index 0000000..e69de29 diff --git a/proto_apng/readme.md b/proto_apng/readme.md new file mode 100644 index 0000000..1ba1590 --- /dev/null +++ b/proto_apng/readme.md @@ -0,0 +1,3 @@ +xarchiver won't open the file + +binwalk -e X.zip does work