英文:
Resize animated .webp using libvips / golang
问题
我有一个Go程序,我想要对一个动画的.webp图像进行调整大小,然后再写入.webp格式。
使用imagemagick,这个方法完美地工作:
exec.Command("magick", tmpWebPFile, "-quality", "70", "-resize", resizeStr, "-layers", "coalesce", outputFile)
为了提高一些速度,我决定尝试使用libvips:
vips webpsave animated.webp out.webp
但是只有第一帧被输出了。
我尝试使用github.com/davidbyttow/govips包:
image, _ := vips.NewImageFromFile(tmpWebPFile)
data, _, _ := image.Export(vips.NewDefaultWEBPExportParams())
os.WriteFile("test.webp", data, 0644)
仍然只有第一帧。
有什么建议吗?
英文:
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
得分: 1
啊,这个方法起作用了:
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)
英文:
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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论