-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
GIF output palette size doubles (from 8 to 16) #3401
Comments
This looks like a quirk of the way that the palette-reuse logic in libvips currently behaves with respect to transparency. The original image has 8 colours:
The output image has 16 colours, but is only using 9 of them:
It looks like the transparency value from entry |
I think we're also seeing this happening in production. Src gif image is 800x800 and 6.2mb - but a 450x450 resized version ends up being 18mb 😅 |
@glomotion Please can you provide a sample image to help confirm this is the same issue. |
@glomotion Thanks, this example is not quite the same issue, as the colour count remains the same for output as input. It looks like the original image was created via gifsicle, which is slow to encode and spends that CPU time doing extra things like optimising LZW clear codes. See dloebl/cgif#51 for a possible future upstream improvement relating to this. This is probably then a performance vs file size trade-off. If you care about file size, animated GIF is usually not the right answer. Converting this image to a video file should result in a file that is at least 5x smaller. |
Hi @glomotion. I had a look:
However, libvips v8.13 added a new option to
I'm not sure if this option is exposed in sharp (I don't have too much context on sharp). Please note that the parameter There are still some possible improvements for cgif on my ToDo:
All things that could be improved on cgif. Note: I had to resize to 330x330, because the maximum allowed file size on GitHub is 10 MB. |
Thanks @dloebl, the two new-ish |
The new Example usage: // interFrameMaxError API available from v0.31.3
await sharp('in.gif', { animated: true })
.gif({ interFrameMaxError: 8 })
.toFile('optim.gif'); |
v0.31.3 now available with support for |
Possible bug
Is this a possible bug in a feature of sharp, unrelated to installation?
npm install sharp
completes without error.node -e "require('sharp')"
completes without error.If you cannot confirm both of these, please open an installation issue instead.
Are you using the latest version of sharp?
sharp
as reported bynpm view sharp dist-tags.latest
.If you cannot confirm this, please upgrade to the latest version and try again before opening an issue.
If you are using another package which depends on a version of
sharp
that is not the latest, please open an issue against that package instead.What is the output of running
npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp
?System:
OS: macOS 12.6
CPU: (8) x64 Apple M1 Pro
Memory: 28.89 MB / 16.00 GB
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 14.17.2 - ~/.nvm/versions/node/v14.17.2/bin/node
npm: 6.14.13 - ~/.nvm/versions/node/v14.17.2/bin/npm
npmPackages:
sharp: ^0.31.1 => 0.31.1
What are the steps to reproduce?
await sharp('input_filename.gif', { animated: true }).toFile('output_filename.gif');
What is the expected behaviour?
Output file size should be the same or nearly the same as the input file size.
Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem
await sharp('input_filename.gif', { animated: true }).toFile('output_filename.gif');
Please provide sample image(s) that help explain this problem
https://media.giphy.com/media/jUwpNzg9IcyrK/giphy.gif
The text was updated successfully, but these errors were encountered: