Save 1 mode PDF using CCITTFaxDecode filter#6470
Merged
hugovk merged 2 commits intopython-pillow:mainfrom Aug 7, 2022
Merged
Conversation
radarhere
commented
Aug 1, 2022
| } | ||
| ) | ||
| ] | ||
| ) |
Member
Author
There was a problem hiding this comment.
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.
This was referenced Aug 1, 2022
Closed
radarhere
commented
Aug 1, 2022
src/PIL/PdfImagePlugin.py
Outdated
| 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 |
Member
Author
There was a problem hiding this comment.
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
radarhere
commented
Aug 1, 2022
| # 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) |
Member
Author
There was a problem hiding this comment.
Rather than updating STRIP_SIZE and needing to reset it afterwards, I've added "strip_size" as a TIFF encoder argument.
This was referenced Aug 22, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #6453
The issue requests the CCITTTaxDecode filter be using to save 1 mode PDFs, to reduce file size.