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

trim() function should only trim transparent pixels but trims black pixels too #2842

Closed
chescos opened this issue Aug 15, 2021 · 1 comment
Closed
Labels

Comments

@chescos
Copy link

chescos commented Aug 15, 2021

What are the steps to reproduce?

Trim the following image:

input

You'll get this result:

output

What is the expected behaviour?

Only trim transparent pixels instead of transparent AND black pixels.

Are you able to provide a minimal, standalone code sample, without other dependencies, that demonstrates this problem?

const fs = require('fs');
const sharp = require('sharp');

const originalFileBuffer = fs.readFileSync('input.png');

(async () => {
    const newFileBuffer = await sharp(originalFileBuffer)
      .trim(1)
      .toFormat('png')
      .toBuffer();

    fs.writeFileSync('output.png', newFileBuffer);
})();

Run the above code snippet with this image as input.png:

input

What is the output of running npx envinfo --binaries --system?

  System:
    OS: Linux 5.11 Ubuntu 21.04 (Hirsute Hippo)
    CPU: (16) x64 AMD Ryzen 7 PRO 5850U with Radeon Graphics
    Memory: 18.05 GB / 30.26 GB
    Container: Yes
    Shell: 5.1.4 - /bin/bash
  Binaries:
    Node: 14.17.5 - /usr/bin/node
    npm: 6.14.14 - /usr/bin/npm
@lovell
Copy link
Owner

lovell commented Aug 15, 2021

Please see #2166

@lovell lovell added question and removed triage labels Aug 15, 2021
@lovell lovell closed this as completed Sep 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants