-
Notifications
You must be signed in to change notification settings - Fork 199
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
Inconsistent behavior when dealing with alpha channels and tiffs #495
Comments
@emcconville I'm happy to help try and debug this, but not sure where to start. My current hypothesis is that some information is lost either when converted to blob or when the Image object is instantiated from blob... |
Happy to have your help. I haven't had time to review the test cases, but |
ok, good to know. I was testing with imagemagick7, so let me repeat the tests with 6 to see what happens. |
ok, using version 6, the difference between The 2nd issue, which I think is far more concerning, still persists while using version 6. For some reason opening, serializing to bytes, and then re-constituting from bytes causes issues. |
Interestingly, I can simplify the test case to this to reproduce the 2nd issue (meaning its not alpha channel related): blob = Image(filename='5-page-pdf.pdf').make_blob()
with Image(blob=blob) as img:
img.format = "tiff"
img.save(filename="test.tiff") So it seems like its either related to to/from bytes, or from-PDF / to-TIFF ? |
I couple of thoughts & tips:
Just some tidbits until I can gather some time to review the test cases. |
Backtracking to 2, I'm guessing I can open a file with Wand to determine the image type, and then open it again passing in the format? Would this improve it at all? It seems like it wouldn't help because if I use Wand to determine the filetype, I wouldn't be able to supply any new information by passing in the format argument a 2nd time. If the format is especially important, is it worth it for me to do something to preprocess the blobs in some other way to determine the format and have that info in metadata somewhere for use when converting to TIFF? |
also, tomorrow I'll test by opening the file with |
my main issue seems most related to #195 now that I've looked into some older tickets |
this blob = open('5-page-pdf.pdf', 'rb').read()
with Image(blob=blob) as img:
img.format = "tiff"
img.save(filename="test.tiff") works, which leads me to believe its related to |
Sounds right. This would hint at the generation loss by raster(ing) a PDF. The Starting to get around to the original test cases. I can recreate the original off / False issues between ImageMagick versions with Wand & CLI by running the variations of ...
For the previous #195 issue, that;s a known limitation with working
Kinda, but this is more in line with ImageTragick, and best practices. When working with blobs blindly, it's important to check the first few bytes to ensure the right decoder is used. For PDFs; that as simple as..
And of course, reject & error handle any unknown payloads. |
For the second issue. It appears to be introduced with
Which is coming from ghostscript. |
.. and can recreate in both wand & CLI directly
This tells me we don't have a Wand issue, but limitations / bug of ImageMagick / ghostscript. FYI, I'm on fedora, and testing with ImageMagick 7.0.10-28 & 6.9.11-27. Both using ghostscript 9.52 |
@emcconville ok, seems like the only change for wand would be to, at most, note the difference between off and false for alpha channels between imagemagic6 and 7, but I can also see the case where one could argue that wand should document wand behavior, not imagemagick behavior. The other issues seem like imagemagick bugs(?). Is it worth my time to file them against imagemagick? You reproduced them with the CLI, not me, so if you'd like to file them be my guest, otherwise I'd probably just copy/paste your examples :D I'm going to close this unless you think there is some reason it should remain open. |
I'll follow up with IM team, but need some more time to dig in. Go ahead and keep this issue open. I'll close it with the doc updates, and Wand 0.6.3 is ready to ship. |
Following up on this. Looks like the PDF files were the cause of the issue. Specifically the ImageType was set to grayscale, but the ICC profile was RGB. In previous version of GhostScript, the ICC was ignored. Current version of GhostScript will respect the ICC profile, and warn / error to stderr. Issue #485 talks about suppressing the error messages from delegates, but I believe in your use-case, you want to capture and parse for PDF messages. Closing for now as this is not exactly a Wand issue (although capturing & releasing child process buffers would be a need feature). |
This is related to #468 so if you want to close this and re-open that, that's fine by me.
I'm using wand 0.6.2, and when I use the PDF still attached to #468 , and run that example code I posted, (I tried both setting
alpha_channel
tooff
andFalse
) I get something far weirder (see attached). The original fix that was posted to stackoverflow also no longer works (but I think that's expected because you now handle it internally).Some sample code:
This works:
This does not:
I've noticed that some TIFF viewers enhance images more than others, the Preview application on macOS is pretty barebones and doesn't do anything to make the TIFF nicer, so the difference between the working and non working examples is that the non working example only has the first and last page with the alpha channel correctly set to off. (When Windows loads the TIFF using Windows Photo Viewer, it looks correct, but I believe its not showing the raw tiff). Not a major deal, I can just use "off", I just expected False to work based on the docs.
This also does not work, but the result is far weirder and likely a bug (TIFF output also attached):
As you can see, the alpha channel is removed, but each page is scaled down and repeated 3 times horizontally on its respective page. Very bizarre
The tiff showing the difference between "off" and False. (The version using off looks correct so I didnt bother posting it).
The tiff showing the result of loading an image as a blob and then trying to remove the alpha channel
The text was updated successfully, but these errors were encountered: