-
-
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
Problem with resizing rgb16 png images when embed() function is used #325
Comments
Hi Tomasz, thanks for the detailed report. I think the problem here is that the background "colour" we're attempting to embed a 16-bit image onto is only 8-bit. It looks like libvips (correctly) assumes 8-bit output for this operation, so all 16-bit values >255 are clipped and hence the output is mostly white. I should be able to fix this fairly easily and you've provided a great test case to use to ensure it doesn't occur again, thank you. |
I've been able to reproduce and apply a quick-fix for this problem locally but it'll probably be a couple of days before I have the chance to address it properly. |
Thanks Lovell for a quick response. I have a workaround that calls Great to hear that the fix is coming soon! |
Commit 61b8674 should now allow for the use of the embed option with 16-bit PNGs, plus adds a test case that would previously have failed. |
This fix is in v0.12.2 now available via npm - thanks again for reporting this! |
Hi Lovell, I confirm that the reported issue is fixed. However my workaround ( The following scenario worked in 0.12.1 and stopped working in 0.12.2 (when the background is set to a transparent color and the aspect ratio is different than the original) The following script is showing the behaviour for different combinations of the background colors and aspect ratios: I also noticed that the var sharp = require('sharp');
// Note: transparent color
var transparent = {r:0, b:0, g:0, a:0};
var opaque = {r:0, b:0, g:0, a:1};
// Scenario 1
// - Output Aspect Ratio == Input Aspect Ratio
// - transparent background
// Result: (sharp 0.12.1) OK
// Result: (sharp 0.12.2) OK
var img = sharp('9Y6MLBf.png');
img.flatten().embed().background(transparent).resize(200,200).toFile('resized-flatten-transparent-200x200-embed.png');
// Scenario 2
// - Output Aspect Ratio != Input Aspect Ratio
// - transparent background
// Result: (sharp 0.12.1) OK
// Result: (sharp 0.12.2) transparent image, colors lost
img = sharp('9Y6MLBf.png');
img.flatten().embed().background(transparent).resize(200,201).toFile('resized-flatten-transparent-200x201-embed.png');
// Scenario 3
// - Output Aspect Ratio != Input Aspect Ratio
// - opaque background
// Result: (sharp 0.12.1) OK
// Result: (sharp 0.12.2) OK
img = sharp('9Y6MLBf.png');
img.flatten().embed().background(opaque).resize(200,201).toFile('resized-flatten-opaque-200x201-embed.png');
// Scenario 4
// - .normalize() called
// Result: (sharp 0.12.1) b&w gradient, colors lost
// Result: (sharp 0.12.2) b&w gradient, colors lost
img = sharp('9Y6MLBf.png');
img.normalize().toFile('normalize.png'); |
Sharp 0.12.1 is incorrectly resizing the following PNG image when
embed()
function is used and the output image has different aspect ratio than the original image.It seems that only rgb16 png images are affected by this issue.
I'm using vips 8.1.1 with libpng 1.5.13.
the original image
Metadata: format=png, width=600, height=600, space=rgb16, channels=4, hasProfile=false, hasAlpha=true

##### the result of img.embed().resize(200, 201)
##### the result of img.embed().resize(200, 200)
##### the result of img.resize(200, 201)
##### Steps to reproduce: 1. Download the source imageExecute the following Node.js script
The text was updated successfully, but these errors were encountered: