-
-
Notifications
You must be signed in to change notification settings - Fork 706
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 prints with black background #1128
Comments
Hello! Could you please provide an example? |
Sure. Here is an example HTML file (saved as a txt file): |
Looks like a problem with CMYK, really like #315. It was supposed to be fixed in Cairo 1.15.4, I don’t know why it’s still there with 1.16. |
Hey thanks! I will double check to make sure I have the latest version of Cairo and post back what I find tomorrow. |
Here is why: the fix has been reverted. Hopefully Cairo is soon gone forever. A quick workaround is to save your JPG file as RGB. |
The bug remains, even without Cairo. |
This still happens .. also converting client pictures, so a solution would be much appreciated |
Some help would be really appreciated on this topic. If you could spend some time to understand what’s wrong in the generated PDF, that would be wonderful. Thank you! |
Theres nothing wrong with the pdf itself, just the color. If you use this image as the background: |
I mean, there’s something in the generated PDF that makes the colors look inverted. Maybe there’s a place where we can tell the PDF that this image is CMYK? Reading the PDF specification and playing with this code could help to find what’s wrong and how to fix this. |
Hi, I was having the same problem where CMYK JPEG images were getting inverted in the PDF output. I was able to get it working by adding the following to images.py
I'm not sure whether this should be done for all CMYK JPEGs (probably not), but I hope it helps. |
That’s really interesting, thanks!
That’s a good question. If someone could find some useful technical information about CMYK JPEGs, that would greatly help understand what we can do to fix this bug. |
What led me to try the Decode trick was this response to an old post about CMYK JPEGs being inverted when extracted from PDF. Section 8.9.5.2 of the pdf spec describes Decode Arrays and lists the default for DeviceCMYK as [0 1 0 1 0 1 0 1], followed by a note: "It is possible to specify a mapping that inverts sample colour intensities by specifying a Dmin value greater than Dmax". This kind of explains why the trick works, but not why it needs to be done in the first place. One thing in common with the "dentex" image posted above and all the other CMYK JPEGs I have tried that exhibit the inversion problem is the following attributes in the EXIF data:
This data can be viewed using exif.tools and the tags are described here. The APP14 tags seem to be specific to Adobe. Perhaps these attributes can be used to determine whether to apply the inversion decode, though I haven't seen a CMYK JPEG that doesn't have these attributes. |
@endaxi Thanks a lot for this investigation.
That’s a great first step! I think that ImageMagick/ImageMagick#6094 is the same problem. The root of the problem seems to be a bug in Photoshop: I suppose that searching for APP14 flags could be a reliable way to know it’s generated by Adobe products, and then add the filter in this case. I think that EXIF tags can be read with Pillow too. Interested in opening a pull request? |
Sure, I can do that. |
Addresses issue [Kozea#1128](Kozea#1128) According to [libjpeg](https://github.com/libjpeg-turbo/libjpeg-turbo/blob/3c17063ef1ab43f5877f19d670dc39497c5cd036/libjpeg.txt#L1569-L1582) "it appears that Adobe Photoshop writes inverted data in CMYK JPEG files" An Adobe JPEG can be identified by the presence of the [APP14](https://exiftool.org/TagNames/JPEG.html#Adobe) segment. The code now checks for the `APP14` segment in `RasterImage` and adds a Decode Array to the XObject when rendering the CMYK JPEG. The value of the Decode Array is the inverse of the default value for DeviceCMYK according to the PDF spec. This has the effect of inverting the inverted image back to normal.
Hi, I'm still having issues with this. A jpg image seems to be inverted (black background).
Please find attached image and generated pdf file. Thanks! |
Hi @alessandroghigi, The fix will be included in version 63.0, it’s not in 62.x. Your image works with the current |
Ok, thanks. |
Hello, when do you plan to release the 63 version any time soon ? |
We’d like to have submit buttons and Color level 4 (#1630) supported before the release. I think that it will take at least 1 month before 63 is released. If you really want to use the |
Addresses issue [Kozea#1128](Kozea#1128) According to [libjpeg](https://github.com/libjpeg-turbo/libjpeg-turbo/blob/3c17063ef1ab43f5877f19d670dc39497c5cd036/libjpeg.txt#L1569-L1582) "it appears that Adobe Photoshop writes inverted data in CMYK JPEG files" An Adobe JPEG can be identified by the presence of the [APP14](https://exiftool.org/TagNames/JPEG.html#Adobe) segment. The code now checks for the APP14 segment in RasterImage and adds a Decode Array to the XObject when rendering the CMYK JPEG. The value of the Decode Array is the inverse of the default value for DeviceCMYK according to the PDF spec. This has the effect of inverting the inverted image back to normal.
I am trying to use Weasyprint to generate pdf reports for a Django web application. The HTML file the report is based on has images in base 64, some of the images generate with a black background instead of a white background. I am trying to understand where this issue might be or how to go about correcting it. Does anyone have any ideas where to start?
The text was updated successfully, but these errors were encountered: