Incorrect page size with different resolutions in x and y directions #181
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Given
and
and
identify -verbose
correctly shows the print height oftest1.png
to be half that oftest1.png
.Unfortunately, both pages of
test.pdf
seem to have the same height.I'm not sure what the root cause might be, but I found a workaround: Use the
-units
flag when creating the images. For example:Then the two pages in the PDF are created with different sizes as expected.
Note that I only tested this with ImageMagick 7 on Arch Linux... Hopefully ImageMagick 6 has similar behavior, if you are using that version.
Thanks for the workaround.
I confirm that it also produces the expected result on ImageMagick 6.9.11.
It would be good to have a better fix, however, rather than running problematic images through imagemagick to add the units field.
This is all part of a python rewrite of gscan2pdf. I'm using img2pdf to create the PDFs before using OCRmyPDF to add the text layer.
I'm manipulating the images internally with PIL, and am trying to use your workaround by adding
density_unit
orjfif_unit
when saving, without success.Do you have any suggestion on how to do this without using
subprocess
andimagemagick
?I see two ways forward:
Depending how urgent this is for you, choose either 1 or 2. :)
It looks like PIL adds an
aspect
field to the image info dict (for PNG files) when units are not defined. This field appears to be undocumented, and grepping through the code, it appears unique to the PNG format handling. And forsave()
, thedpi
option can be set.So for the cases of handling PNG files without resolution units defined, I guess you could trying querying
aspect
and setdpi
when saving the image.This was a good tip. Thanks. My code with this workaround now produces the desired result.
@josch Testing with the latest commit with a PNG that does have a DPI set, img2pdf changes the DPI to 96x96. PIL sets the
dpi
field instead ofaspect
in that case.Shouldn't img2pdf keep the DPI settings from the image if present?
Without considering any other side effects this might have, this is the change I tested that preserves the setting:
Thank you for making me aware. It seems I had pushed too early. This is the fixed commit:
fb9537d8b7
Thanks! Confirmed working now :)