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

Wrong colors in composite with blend:'dest-in' + resize since v0.30.2 #3334

Closed
3 tasks done
tophf opened this issue Aug 12, 2022 · 2 comments
Closed
3 tasks done

Wrong colors in composite with blend:'dest-in' + resize since v0.30.2 #3334

tophf opened this issue Aug 12, 2022 · 2 comments

Comments

@tophf
Copy link

tophf commented Aug 12, 2022

  • Running npm install sharp completes without error.
  • Running node -e "require('sharp')" completes without error.
  • 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: Windows 10 10.0.19044
    CPU: (8) x64 Intel(R) Core(TM) i7-3770K CPU @ 3.50GHz
    Memory: 8.27 GB / 31.95 GB
  Binaries:
    Node: 16.7.0 - C:\app\dev\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.20.3 - C:\app\dev\nodejs\npm.CMD
  npmPackages:
    sharp: ^0.30.7 => 0.30.7

What are the steps to reproduce?

  1. Resize a semi-transparent image using the code below
  2. The result is an overexposed image

What is the expected behaviour?

The image is half-transparent as shown in the table below.

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

require('sharp')('icon.png').composite([{
  input: Buffer.from([255, 255, 255, 256 * 0.5]),
  raw: { width: 1, height: 1, channels: 4 },
  tile: true,
  blend: 'dest-in',
}]).resize({ width: 64 }).toFile('icon-t.png');
Type Source Expected Observed
Image icon icon-t icon-t

Looking at v0.30.1...v0.30.2 I guess the bug was introduced in c620025 released in 0.30.2. Further investigation showed it was partly fixed - for non-resized composite - in 23033e2 released in 0.30.3.

@lovell
Copy link
Owner

lovell commented Aug 21, 2022

Thanks for reporting this, the changes to composite you discovered did cause this. Commit a618ce7 now ensures the (implicit) unpremultiply operation occurs before composite and adds a test that would previously have failed. This will be included in v0.31.0.

@lovell
Copy link
Owner

lovell commented Sep 5, 2022

v0.31.0 now available with the fix, thanks for reporting this.

@lovell lovell closed this as completed Sep 5, 2022
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