-
Notifications
You must be signed in to change notification settings - Fork 207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resizing GIFs is failing on linux, hanging / breaking on macOS for larger GIFs #255
Comments
What version of libvips are you using? Native animated GIF support is only present since 8.12. Before that it likely falls back to imagemagick which is HORRIBLE for animated gifs. |
Hi @aksdb! Sorry it's been a while 😅 Following @vansante's PR, I cleaned out all of my brew packages and did a clean install on my M1 Max MBP as follows:
I was then able to resize a few gifs successfully, including ones larger than the broken gif linked above. I can see that @vansante's gifsave PR substantially improved performance. However, for some reason that one gif is still failing to resize. The error I'm getting is:
Is there something wrong with the gif? I noticed that it also doesn't show its size in Finder which is a little odd. |
Update @davidbyttow @aksdb @vansante -- I was able to resize the same GIF I'm unable to resize with this library using ezgif.com so it's definitely possible. I'm wondering if this is a bug with the gifsave library? I've hosted the two gifs for you to test with in an S3 bucket because they're too big for Github: The code I'm using to resize it is:
Where Resize is defined:
And EncodeToFile effectively calls this:
|
I had the same problem when trying to resize a GIF
This is my test code func Normalize(buf []byte) (_ []byte, _ *vips.ImageMetadata, err error) {
imageType := vips.DetermineImageType(buf)
if imageType == vips.ImageTypeUnknown {
return nil, nil, fmt.Errorf("unknown image type")
}
importParams := vips.NewImportParams()
importParams.NumPages.Set(-1)
imageRef, err := vips.LoadImageFromBuffer(buf, importParams)
if err != nil {
return nil, nil, err
}
defer imageRef.Close()
err = imageRef.AutoRotate()
if err != nil {
return nil, nil, err
}
originWidth := imageRef.Width()
if originWidth > MAX_WIDTH {
scale := MAX_WIDTH / float64(originWidth)
err = imageRef.Resize(scale, vips.KernelLanczos3)
if err != nil {
return nil, nil, err
}
}
exportParams := vips.NewDefaultExportParams()
exportParams.Quality = QUALITY
exportParams.Lossless = false
exportParams.Interlaced = true
exportParams.Compression = 6
exportParams.StripMetadata = true
return imageRef.Export(vips.NewDefaultExportParams())
} |
Hi @Elad-Laufer and @davidbyttow! I wanted to try out the GIF resizing on my server in a Go container-based lambda function.
Unfortunately, while I was able to resize a GIF locally with the latest version of govips, when I tried to resize it in my lambda function I got this error:
From the name of the missing class, I assumed that govips might be depending on imagemagick so I installed that but still got the same error.
Do you have any idea what could be causing this?
My Dockerfile is as follows:
Additionally, I was able to resize this first GIF locally on macOS:
But this second, larger GIF caused one core of my CPU (M1 Max) to be pegged at 100% for a couple of minutes while using ~800MB of RAM before it spat out the following broken GIF image which seems to just have placed all of the frames vertically in one super tall image.
These files were too large to upload to Github directly so I put them in an S3 bucket to share with you:
Original:
https://logan-shared-files.s3.us-west-2.amazonaws.com/FAILS-TO-RESIZE.gif
Broken resized:
https://logan-shared-files.s3.us-west-2.amazonaws.com/FAILED-TO-RESIZE.gif
The text was updated successfully, but these errors were encountered: