-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Save 1 mode PDF using CCITTFaxDecode filter #6470
Conversation
} | ||
) | ||
] | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://opensource.adobe.com/dc-acrobat-sdk-docs/standards/pdfstandards/pdf/PDF32000_2008.pdf#page=38 indicates that K should be <0 for Group 4 encoding
On the next page of that document, it describes BlackIs1, that allows the colors to be inverted.
src/PIL/PdfImagePlugin.py
Outdated
@@ -161,6 +180,11 @@ def _save(im, fp, filename, save_all=False): | |||
|
|||
if filter == "ASCIIHexDecode": | |||
ImageFile._save(im, op, [("hex", (0, 0) + im.size, 0, im.mode)]) | |||
elif filter == "CCITTFaxDecode": | |||
original_strip_size = TiffImagePlugin.STRIP_SIZE | |||
TiffImagePlugin.STRIP_SIZE = math.ceil(im.width / 8) * im.height |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In writing this PR, I found that it was necessary to save the image as a single strip. This has actually been pointed out before, in #5740
@@ -1684,7 +1684,8 @@ def _save(im, fp, filename): | |||
stride = len(bits) * ((im.size[0] * bits[0] + 7) // 8) | |||
# aim for given strip size (64 KB by default) when using libtiff writer | |||
if libtiff: | |||
rows_per_strip = 1 if stride == 0 else min(STRIP_SIZE // stride, im.size[1]) | |||
im_strip_size = encoderinfo.get("strip_size", STRIP_SIZE) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than updating STRIP_SIZE
and needing to reset it afterwards, I've added "strip_size" as a TIFF encoder argument.
Resolves #6453
The issue requests the CCITTTaxDecode filter be using to save 1 mode PDFs, to reduce file size.