-
-
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
PDFs and 1 bit pixels #1775
Comments
Not sure what's going on… should we call this a bug? |
So I investigated this a bit and it is a bug that existed pre-fork as best I can tell. The lines in question are in PdfImagePlugin.py(line:173): if filter == "/ASCIIHexDecode":
if bits == 1:
# FIXME: the hex encoder doesn't support packed 1-bit
# images; do things the hard way...
data = im.tobytes("raw", "1")
im = Image.new("L", (len(data), 1), None)
im.putdata(data)
ImageFile._save(im, op, [("hex", (0, 0)+im.size, 0, im.mode)]) The problem lies in the I would assume anyone using mode 1 is probably wanting to keep their output file super small. The ASCIIHex filter has no 'image' compression or data compression and generates a 5.5 MB file in the example. The equivalent PNG is 421 Bytes. The ideal situation would be for someone to implement one of the lossless algorithms and supply a flag to the
|
#3827 has been merged, so the dimensions problem should now be fixed. However, there seems to also be a request for compression here. |
I've created PR #5430 to add DCTDecode compression for 1-bit PDFs, reducing the 5mb PDF here to 34kb. |
I've created PR #6470, which uses CCITTTaxDecode compression, reducing the PDF down to 1kb. |
I posted this question on Stack Overflow before realizing that perhaps I should post it here.
I'm trying to create a PDF of a complicated black-and-white rectangular grid, nominally 7 inches wide by 10 inches tall. I'm using Pillow to do the conversion. If I specify a PNG, everything works fine (that is, the aspect ratio is 7 by 10). If I specify a PDF, the output is 200 inches wide and 0.04 inches tall. What's going on?
Incidentally, if I set
mode='RGB'
, then the output PDF dimensions are correct, but Pillow performs a JPEG encoding of the image. JPEG converts my sharp black and white grid into smoother shades of gray (which is anathema for my application).The text was updated successfully, but these errors were encountered: