question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

PNG to AVIF. Prebuilt & custom-built sharp outputs larger file size w/ bigger `effort`

See original GitHub issue

Possible bug

Is this a possible bug in a feature of sharp, unrelated to installation?

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.

Are you using the latest version of sharp?

  • I am using the latest version of sharp as reported by npm view sharp dist-tags.latest.

What is the output of running npx envinfo --binaries --system --npmPackages=sharp --npmGlobalPackages=sharp?

  System:
    OS: macOS 13.0
    CPU: (10) arm64 Apple M1 Pro
    Memory: 689.75 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 18.11.0 - /opt/homebrew/bin/node
    Yarn: 1.22.19 - /opt/homebrew/bin/yarn
    npm: 8.19.2 - /opt/homebrew/bin/npm
  npmPackages:
    sharp: 0.31.1 => 0.31.1 

or another system bearing the same problem:

  System:
    OS: Linux 5.15 Amazon Linux 2
    CPU: (8) arm64 unknown
    Memory: 6.85 GB / 7.76 GB
    Container: Yes
    Shell: 4.2.46 - /bin/bash
  Binaries:
    Node: 16.17.1 - /var/lang/bin/node
    npm: 8.15.0 - /var/lang/bin/npm

What are the steps to reproduce?

  1. Install sharp with pre-built binaries
  2. Use image from example.png with the provided code snippet.
  3. Observe the console to see: the higher effort results in bigger file size

On my device(s), it prints as:

Effort 0 size: 342380
Effort 4 size: 356314
Effort 9 size: 361679

What is the expected behaviour?

Increase in effort doesn’t make the size bigger (at least keeps it the same as with the lower effort)

Please provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem

const checkEffortAndSize = async (effort) => {
  const cmd = sharp(`./example.png`)
  const buffer = await cmd
    .avif({ quality: 64, effort })
    .toBuffer()

  console.info(`Effort ${effort} size: ${buffer.byteLength}`)
}

await Promise.all([checkEffortAndSize(0), checkEffortAndSize(9)])

Please provide sample image(s) that help explain this problem

example.zip

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lovellcommented, Oct 26, 2022

Thanks for the update, and no worries, as you say this is a question for the libaom maintainers.

The small file size difference probably relates to chroma subsampling (sharp defaults to 4:4:4, i.e. none, whereas libheif defaults to 4:2:0).

0reactions
o-alexandrovcommented, Nov 5, 2022

Just for the record, libaom maintainers think libaom is working as expected.

  • they think cpu-used (their internal parameter that is connected to sharp’s effort parameter) should affect the processing quality, which in turn results in a different output
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Modern Image Formats: AVIF And WebP
Smaller file size directly impacts the Largest contentful Paint (LCP) metric for the ... (e.g., PNG images with transparent backgrounds) ...
Read more >
PNG to AVIF (Online & Free) - Convertio
AVIF file size is 10 times smaller than JPEG with the same image quality. AVIF supports not only Standard Dynamic Range (SDR) images...
Read more >
AVIF Converter - unlimited free conversions | avif.io
Convert all image types to AVIF for free. Compress your images now! ... supports png · jpg · webp · gif...
Read more >
config "quality" setting for AVIF files doesn't affect generated ...
png , note the generated AVIF file size; expected to get a larger size with quality 50, but got the same AVIF file...
Read more >
Load Your Images Faster with the Next-Gen AVIF Format
Generally speaking, if you convert a JPEG or PNG image to a WebP image, the resulting file size will be 30% smaller and...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found