From 900346d4308d0afed54bb64e6b65b0021e99fc01 Mon Sep 17 00:00:00 2001 From: "James R. Barlow" Date: Sat, 13 Feb 2016 08:59:52 +0100 Subject: [PATCH] src/img2pdf.py: add get_fixed_dpi_layout_fun --- src/img2pdf.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/img2pdf.py b/src/img2pdf.py index 7d24556..446fa7a 100755 --- a/src/img2pdf.py +++ b/src/img2pdf.py @@ -841,6 +841,17 @@ def default_layout_fun(imgwidthpx, imgheightpx, ndpi): return pagewidth, pageheight, imgwidthpdf, imgheightpdf +def get_fixed_dpi_layout_fun(fixed_dpi): + """Layout function that overrides whatever DPI is claimed in input images. + + >>> layout_fun = get_fixed_dpi_layout_fun((300, 300)) + >>> convert(image1, layout_fun=layout_fun, ... outputstream=...) + """ + def fixed_dpi_layout_fun(imgwidthpx, imgheightpx, ndpi): + return default_layout_fun(imgwidthpx, imgheightpx, fixed_dpi) + return fixed_dpi_layout_fun + + # given one or more input image, depending on outputstream, either return a # string containing the whole PDF if outputstream is None or write the PDF # data to the given file-like object and return None