Skip to content
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

WebP input can ignore resize kernel #3516

Closed
rnavarroz opened this issue Jan 5, 2023 · 4 comments
Closed

WebP input can ignore resize kernel #3516

rnavarroz opened this issue Jan 5, 2023 · 4 comments

Comments

@rnavarroz
Copy link

Possible bug

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

  • [ x] Running npm install sharp completes without error.
  • [ x] Running 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?

  • [ x] 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: Linux 5.15 Ubuntu 22.04.1 LTS 22.04.1 LTS (Jammy Jellyfish)
    CPU: (8) x64 Intel(R) Core(TM) i5-10210U CPU @ 1.60GHz
    Memory: 1.93 GB / 15.27 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 16.14.0 - ~/.config/nvm/versions/node/v16.14.0/bin/node
    npm: 8.3.1 - ~/.config/nvm/versions/node/v16.14.0/bin/npm

What are the steps to reproduce?

Attempt to read in the webp image with transparency.

What is the expected behaviour?

Changing the value of the kernel should show a different output of size in bytes but always is the same regardless of which kernel uses:
nearest, cubic, mitchell, lanczos2,lanczos3

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

 const { data, info } = await sharp('transparency-linux.wep').resize(293, 300, {
    withoutEnlargement: true,
    fit: 'inside',
    kernel: 'mitchell'
  } )
    .toBuffer({ resolveWithObject: true });
  console.log(info);

{
  format: 'webp',
  width: 293,
  height: 300,
  channels: 4,
  premultiplied: false,
  size: 9420
}
 const { data, info } = await sharp('transparency-linux.wep').resize(293, 300, {
    withoutEnlargement: true,
    fit: 'inside',
    kernel: 'cubic'
  } )
    .toBuffer({ resolveWithObject: true });
  console.log(info);

{
  format: 'webp',
  width: 293,
  height: 300,
  channels: 4,
  premultiplied: false,
  size: 9420
}

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

transparency-linux.tar.gz

@lovell lovell added question and removed triage labels Jan 6, 2023
@lovell
Copy link
Owner

lovell commented Jan 6, 2023

Hi, did you see the fastShrinkOnLoad option of resize()? Setting it to false will prevent the use of libwebp's scaling and instead use the kernel.

(I've added a brief note about this to the docs via commit e827358 )

@rnavarroz
Copy link
Author

I just did and try it but there is not different on the sizes:

  const { data, info } = await sharp('transparency-linux.webp')
  .resize(293, 300, {
    withoutEnlargement: true,
    fit: 'inside',
    kernel: 'mitchell',
    fastShrinkOnLoad: false
  })
  .toBuffer({ resolveWithObject: true });
  console.log(info);

result

{
  format: 'webp',
  width: 293,
  height: 300,
  channels: 4,
  premultiplied: false,
  size: 9420
}

@lovell
Copy link
Owner

lovell commented Jan 17, 2023

Thank you, I've been able to reproduce this. Commit c150263 alters the behaviour of WebP input to ensure it respects the fastShrinkOnLoad and therefore kernel option. This will be in v0.32.0.

@lovell lovell added this to the v0.32.0 milestone Jan 17, 2023
@lovell lovell changed the title kernel option does not work WebP input can ignore resize kernel Jan 17, 2023
@lovell
Copy link
Owner

lovell commented Mar 24, 2023

sharp v0.32.0 is now available with this fix, thanks for reporting.

@lovell lovell closed this as completed Mar 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants