davidbyttow / govips

A lightning fast image processing and resizing library for Go
MIT License
1.25k stars 196 forks source link

LoadThumbnailFromBuffer causes jpegload_buffer issue #343

Closed sfaujour closed 1 year ago

sfaujour commented 1 year ago

Hi, i'm getting this issue below when using the vips.LoadThumbnailFromBuffer function.

Im running my application with go 1.19 within an ubuntu 22.04 and vips 8.12.1.

jpegload_buffer: no property named `n'

Stack:
goroutine 8 [running]:
runtime/debug.Stack()
    /usr/lib/go-1.18/src/runtime/debug/stack.go:24 +0x68
github.com/davidbyttow/govips/v2/vips.handleVipsError()
    /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/error.go:38 +0x3c
github.com/davidbyttow/govips/v2/vips.handleImageError(0x400029e0b0?)
    /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/error.go:23 +0x28
github.com/davidbyttow/govips/v2/vips.vipsThumbnailFromBuffer({0x4000c78000?, 0x13?, 0x4000158cb8?}, 0x1?, 0x1?, 0x0?, 0xffff7efe15b8?, 0x4000158d68)
    /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/resample.go:111 +0x148
github.com/davidbyttow/govips/v2/vips.LoadThumbnailFromBuffer({0x4000c78000, 0x195648, 0x1ac000}, 0x400?, 0x10?, 0xffff7efe15e0?, 0x4000158d58?, 0x4134a4?)
    /root/go/pkg/mod/github.com/davidbyttow/govips/v2@v2.11.0/vips/image.go:463 +0x64
gitlab.com/application/internal/handler/processor/vips.(*Routine).Resize(0x4000126010, {0x4000c78000, 0x195648, 0x1ac000}, 0x40000acef8?, 0x9c11cc?)
var err error

intSet := vips.IntParameter{}
intSet.Set(-1)

params := vips.NewImportParams()
params.NumPages = intSet

err = vips.LoadThumbnailFromBuffer(blob, int(width), int(height), vips.InterestingNone, vips.SizeBoth, params)

When using the NewThumbnailFromBuffer function, or setting the params to nil in the above function, it's working, but it would be great that the other function would work too, as i want to resize gif's as well, and there i need the ImportParams.

sfaujour commented 1 year ago

This issue can be closed as i found the issue here. The import params with "NumPages" will also be applied to images with JPG format, and probably others too. The libvips library doesn't accept this option, and the above error is thrown.

So the "Workaround" is to use vips.DetermineImageType(blob) and check if this is a GIF, and setting afterwards the NumPages.