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
Multi-strip usage when encoding group4 TIF breaks use in PDF #5740
Comments
If you understand #5514, and acknowledge that this is an obscure use case, is this hack interesting to you at all? It would let you override the values for ROWSPERSTRIP, STRIPBYTECOUNTS and STRIPOFFSETS. from PIL import Image, TiffImagePlugin
pillow__getitem__ = TiffImagePlugin.ImageFileDirectory_v2.__getitem__
def __getitem__(self, tag):
overrides = {
TiffImagePlugin.ROWSPERSTRIP: 500,
TiffImagePlugin.STRIPBYTECOUNTS: 31500,
TiffImagePlugin.STRIPOFFSETS: 0
}
return overrides.get(tag, pillow__getitem__(self, tag))
TiffImagePlugin.ImageFileDirectory_v2.__getitem__ = __getitem__
im = Image.open("Tests/images/hopper_g4_500.tif")
im.save("out.tif", compression="group4") |
Perhaps adding a constant that can be overridden instead of the hard-coded 64 KB here could be a neat way to address this? |
@radarhere thanks a lot for your input! Yes, that hack is indeed interesting to me because even if @kmilos solution is implemented in a future pillow version, we cannot travel back in time and thus I would need a solution for those pillow versions that have #5514 applied but do not yet have a constant that can be overridden. Unfortunately, I'm afraid that I'm not getting your code snippet to work. Did you test it? I suspect that how it is written, the values will not be overwritten by the IFD writer. |
Perhaps |
Yes, I tried that already and the resulting image is corrupted. |
I've tested the code I wrote, yes. Could we get a copy of your original image, and the values you're trying to write? |
Sorry, it was my mistake. Of course I have to reset Thanks a lot! :) |
#6470 has been merged, so |
Thank you @radarhere, using But is there a way (other than checking and comparing the PIL version) to check whether the current version of PIL supports |
Not directly, no. But if you don't like version numbers for some reason, perhaps you could check indirectly. Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
>>> Image.init()
1
>>> "MPO" in Image.SAVE_ALL
True #6444 added support for saving multiple MPO frames, as will be released in Pillow 9.3.0 for the first time. So by checking if Pillow supports saving multiple MPO frames, you are checking that Pillow is >= 9.3.0 (presuming that you aren't concerned about people compiling Pillow from source in between versions). |
Hi,
since #5514, group4 tiff images are not anymore saved as a single strip. This breaks the use-case of utilizing PIL for encoding images as group4 for inclusion in PDF documents, as the PDF format only supports a single group4 encoded strip per image.
Please allow for a way to force single-strip group4 encoding to restore this functionality, maybe by allowing to specify the maximum strip length?
(I realize this sounds a lot like https://xkcd.com/1172/ 😄)
The text was updated successfully, but these errors were encountered: