mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-25 14:44:45 +03:00
Allow asymmetric PDF export resolution
Allow PDF exporting resolution to be specified as a tuple too, to get asymmetric DPIs sometimes used by sticker/inkjet printers, e.g 600x1200dpi.
This commit is contained in:
parent
4f3b44960f
commit
f8d46cc79c
|
@ -56,6 +56,11 @@ def _save(im, fp, filename, save_all=False):
|
||||||
existing_pdf = PdfParser.PdfParser(f=fp, filename=filename, mode="w+b")
|
existing_pdf = PdfParser.PdfParser(f=fp, filename=filename, mode="w+b")
|
||||||
|
|
||||||
resolution = im.encoderinfo.get("resolution", 72.0)
|
resolution = im.encoderinfo.get("resolution", 72.0)
|
||||||
|
# Allows the user to specify either a 1D resolution or 2D resolution.
|
||||||
|
if not isinstance(resolution,(list,tuple)):
|
||||||
|
resolution2D = (resolution,resolution)
|
||||||
|
else:
|
||||||
|
resolution2D = resolution
|
||||||
|
|
||||||
info = {
|
info = {
|
||||||
"title": None if is_appending else os.path.splitext(
|
"title": None if is_appending else os.path.splitext(
|
||||||
|
@ -211,8 +216,8 @@ def _save(im, fp, filename, save_all=False):
|
||||||
MediaBox=[
|
MediaBox=[
|
||||||
0,
|
0,
|
||||||
0,
|
0,
|
||||||
int(width * 72.0 / resolution),
|
int(width * 72.0 / resolution2D[0]),
|
||||||
int(height * 72.0 / resolution)
|
int(height * 72.0 / resolution2D[1])
|
||||||
],
|
],
|
||||||
Contents=contents_refs[pageNumber])
|
Contents=contents_refs[pageNumber])
|
||||||
|
|
||||||
|
@ -221,8 +226,8 @@ def _save(im, fp, filename, save_all=False):
|
||||||
|
|
||||||
page_contents = PdfParser.make_bytes(
|
page_contents = PdfParser.make_bytes(
|
||||||
"q %d 0 0 %d 0 0 cm /image Do Q\n" % (
|
"q %d 0 0 %d 0 0 cm /image Do Q\n" % (
|
||||||
int(width * 72.0 / resolution),
|
int(width * 72.0 / resolution2D[0]),
|
||||||
int(height * 72.0 / resolution)))
|
int(height * 72.0 / resolution2D[1])))
|
||||||
|
|
||||||
existing_pdf.write_obj(contents_refs[pageNumber],
|
existing_pdf.write_obj(contents_refs[pageNumber],
|
||||||
stream=page_contents)
|
stream=page_contents)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user