-
-
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
Image corruption when resizing and converting to jpg #249
Comments
Hello, the saturated output you're experiencing looks like it could be related to the (un)pre-multiplication stage added in v0.11.0. This is designed to improve the quality of transparent image resizing and allow alpha compositing and is applied for any input image with an alpha channel. libvips 8.1.0+ provides a native (un)premultiply operation for us and for earlier versions sharp uses it's own (un)pre-multiplication logic (thanks to @gasi). I've tried your sample image with both libvips' and sharp's version of this logic and both work for me with the latest libvips master code. My best guess is that we may have run into something that's been fixed within the last year in libvips itself since 7.40.6. Are you able to test using a more recent version of libvips to help narrow this down? A possible quick fix here might be to use |
Using flatten, the image is converted correctly. It seems like I can't get a working build of libvips 8 on Debian 8. |
@compeak Glad to hear the quick fix worked for you. I'm still a little concerned there may be a problem with sharp's premultiply code on older versions of libvips. If anyone else should run into this, please add more examples here and I'll re-open the issue. |
@lovell Thank you for your help. |
Hmmm, shouldn’t (un)premultiplication only happen for compositing images with alpha channel? In this case, @compeak is only resizing and converting from PNG to JPEG. |
I take that back. Looks like it happens for any affine transform: Lines 495 to 500 in dee9ca3
|
Thanks @gasi, I think the use of premultiply with affine is the correct behaviour. In addition, thanks to the investigation into this problem, I may have discovered another relating to the use of normalisation and/or gamma correction with alpha channels. |
Agreed, I believe it is too.
Sounds promising. Based on my (limited) experience working with (un)premultiplication, errors were usually subtle especially if images were close to fully opaque or fully transparent. Sometimes errors were big, but that generally meant the sign of some multiplication was wrong and that would be an obvious error we’d see more frequently. Good luck on your investigation! |
@lovell Wow, nice find and fix! 👍 |
So @lovell has fixed the problem in 0.11.1? I'm running on 0.11.2, but the problem is still there. Any suggestions? Thanks. |
@baoshan Which version of libvips are you using? I think the summary was that 7.40.6 can fail but 8.0.2 is OK. The workaround for earlier versions is to explicitly add the |
Does that mean I have 8.0.2? But still requires |
@baoshan Sorry, my mistake, I meant to say that libvips v8.1.0 is (or will be) OK. Glad to hear |
Thanks. Sorry for didn't get the summary correct at first. |
I've had the same issue.
Using flatten() solved the issue for me as well. |
When I try to resize and convert a png to jpg sharp outputs a corrupted image.
Input:
convert-resize.js
Output:
This seems to happen every time a png gets converted to jpg and resized to a smaller size.
vipsthumbnail test.png -o tn_%s.jpg --size 1000
produces correct output.I used sharp 0.11.0 and vips 7.40.6 on Debian 8.1.
The text was updated successfully, but these errors were encountered: