DPI "units" don't work in pagesize spec #27

Closed
opened 2021-04-25 19:57:46 +00:00 by josch · 0 comments
Owner

By jbarlow83 on 2016-02-05T23:03:32.741Z

Using Python 3

$ img2pdf --output output.pdf --imgsize 300dpix300dpi tests/input.jpg 

img2pdf: error: argument -s/--imgsize: width is not a floating point number: 300d

However, other units do work, e.g. this is fine.

img2pdf --output output.pdf --imgsize 300cmx300cm tests/input.jpg 

By josch on 2016-02-10T06:20:14.052Z


Ah, I knew there was something that I hadn't implemented yet before hitting the release button...

So, the story is, the --help output for the --imgsize option talks about the dpi and % units but neither of them is implemented. The reason is, that with the current structure, it would be quite hard to support these types of unit.

Would you be interested in having this feature?

Otherwise, I'll just remove them from the --help text.


By jbarlow83 on 2016-02-10T07:49:15.584Z


It's definitely useful. In a lot of cases input images are missing DPI information or have the wrong DPI set. In these cases I wouldn't want to calculate the page size, I just want to set the DPI to something reasonable. As an example use case, I work with scanned maps that often have the wrong DPI set on the scanned image. Often the map with have a scale bar whose length in pixels can be measured, and from there the scanning DPI can be determined.

It's really just the input argument parser that's broken. The following currently works for setting DPI:

    imgsize = ((img2pdf.ImgSize.dpi, dpi), (img2pdf.ImgSize.dpi, dpi))
    layout_fun = img2pdf.get_layout_fun(None, imgsize, None, None, None)
    out = img2pdf.convert(... layout_fun=layout_fun)

By josch on 2016-02-10T08:33:16.027Z


oh indeed - I'm impressed I implemented it this far! The parser should be fixed now. Thanks!


By josch on 2016-02-10T08:33:16.176Z


Status changed to closed

*By jbarlow83 on 2016-02-05T23:03:32.741Z* Using Python 3 ``` $ img2pdf --output output.pdf --imgsize 300dpix300dpi tests/input.jpg img2pdf: error: argument -s/--imgsize: width is not a floating point number: 300d ``` However, other units do work, e.g. this is fine. ``` img2pdf --output output.pdf --imgsize 300cmx300cm tests/input.jpg ``` --- *By josch on 2016-02-10T06:20:14.052Z* --- Ah, I *knew* there was something that I hadn't implemented yet before hitting the release button... So, the story is, the `--help` output for the `--imgsize` option talks about the `dpi` and `%` units but neither of them is implemented. The reason is, that with the current structure, it would be quite hard to support these types of unit. Would you be interested in having this feature? Otherwise, I'll just remove them from the `--help` text. --- *By jbarlow83 on 2016-02-10T07:49:15.584Z* --- It's definitely useful. In a lot of cases input images are missing DPI information or have the wrong DPI set. In these cases I wouldn't want to calculate the page size, I just want to set the DPI to something reasonable. As an example use case, I work with scanned maps that often have the wrong DPI set on the scanned image. Often the map with have a scale bar whose length in pixels can be measured, and from there the scanning DPI can be determined. It's really just the input argument parser that's broken. The following currently works for setting DPI: imgsize = ((img2pdf.ImgSize.dpi, dpi), (img2pdf.ImgSize.dpi, dpi)) layout_fun = img2pdf.get_layout_fun(None, imgsize, None, None, None) out = img2pdf.convert(... layout_fun=layout_fun) --- *By josch on 2016-02-10T08:33:16.027Z* --- oh indeed - I'm impressed I implemented it this far! The parser should be fixed now. Thanks! --- *By josch on 2016-02-10T08:33:16.176Z* --- Status changed to closed
josch closed this issue 2021-04-25 19:57:47 +00:00
josch changed title from DPI "units" don't work in pagesize spec to DPI "units" don't work in pagesize spec 2021-04-27 13:57:25 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: josch/img2pdf#27
No description provided.