Resize animated .webp using libvips / golang

458 views Asked by At

I have a Go program where I want to take an animated .webp image, resize it and then write it to .webp again.

This worked flawlessly using imagemagick:

exec.Command("magick", tmpWebPFile, "-quality", "70", "-resize", resizeStr, "-layers", "coalesce", outputFile)

In order to gain some speed, I decided to try with libvisp:

vips webpsave animated.webp out.webp

Only thing that comes out is the first frame.

I tried using the github.com/davidbyttow/govips package:

image, _ := vips.NewImageFromFile(tmpWebPFile)
data, _, _ := image.Export(vips.NewDefaultWEBPExportParams())
os.WriteFile("test.webp", data, 0644)

Still just the first frame.

Any suggestions?

1

There are 1 answers

1
estrar On

Ah, this did the trick:

params := vips.NewImportParams()
params.NumPages.Set(-1)
image, _ := vips.LoadImageFromFile(tmpWebPFile, params)
image.ThumbnailWithSize(width, newHeight, vips.InterestingAll, vips.SizeDown)
data, _, _ := image.ExportWebp(&vips.WebpExportParams{
    Quality:       70,
})
os.WriteFile("out.webp", data, 0644)