-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Closed
Labels
BugAny unexpected behavior, until confirmed feature.Any unexpected behavior, until confirmed feature.Conversion
Milestone
Description
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).
import PIL
from PIL import Image
# Let's consider a 7" x 10" rectangle of pixels
inches_wide=7
inches_tall=10
dpi=200
num_pixel_rows=inches_tall*dpi
num_pixel_cols=inches_wide*dpi
# Make an image
mode='1'
img = Image.new( mode, (num_pixel_cols,num_pixel_rows))
img.info['dpi'] = (dpi,dpi)
# Saving it as PNG, we get a black rectangle, as expected.
img.save('big_rectangle.png','png',resolution=dpi)
# Saving it as a PDF, we get a 200" x 0.04" all-white line?!
img.save('big_rectangle.pdf','pdf',resolution=dpi)
# Versioning info:
print 'PILLOW',PIL.PILLOW_VERSION
print 'PIL',PIL.VERSION
# My output:
# PILLOW 3.1.1
# PIL 1.1.7Metadata
Metadata
Assignees
Labels
BugAny unexpected behavior, until confirmed feature.Any unexpected behavior, until confirmed feature.Conversion