feat: automatic load pages in animated images (#231)

* feat: automatic load pages in animated images

Signed-off-by: STRRL <im@strrl.dev>

* chore: remove destination file during test

Signed-off-by: STRRL <im@strrl.dev>

* chore: change import param code style

Signed-off-by: STRRL <im@strrl.dev>

---------

Signed-off-by: STRRL <im@strrl.dev>
This commit is contained in:
Zhou Zhiqiang 2023-06-15 14:08:08 +08:00 committed by GitHub
parent f5eda9eaed
commit 90680bef6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 0 deletions

View File

@ -165,8 +165,11 @@ func webpEncoder(p1, p2 string, quality int, extraParams ExtraParams) error {
var buf []byte
var boolFalse vips.BoolParameter
boolFalse.Set(false)
var intMinusOne vips.IntParameter
intMinusOne.Set(-1)
img, err := vips.LoadImageFromFile(p1, &vips.ImportParams{
FailOnError: boolFalse,
NumPages: intMinusOne,
})
if err != nil {
return err

View File

@ -96,6 +96,11 @@ func TestWebPEncoder(t *testing.T) {
_ = os.Remove(dest)
}
func TestAnimatedGIFWithWebPEncoder(t *testing.T) {
runEncoder(t, "./pics/gif-animated.gif", dest)
_ = os.Remove(dest)
}
func TestAvifEncoder(t *testing.T) {
// Only one file: img_over_16383px.jpg might cause memory issues on CI environment
assert.Nil(t, avifEncoder("./pics/big.jpg", dest, 80, ExtraParams{Width: 0, Height: 0}))

BIN
pics/gif-animated.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB