Page 1 of 1

[solved] PNG to PDF with specific size and pixel density

Posted: 2018-12-11T11:28:12-07:00
by monpantalon
Hi,

I have a PNG image with arbitrary physical dimension but 222 x 308 pixels, and would like to make it into a PDF with physical dimension 111 x 154 millimeters and >= 300dpi, with no smoothing, i.e. visible pixels.

I have tried running the command

Code: Select all

convert in.png -size 111x154 -units millimeter out.pdf

or also (with the obvious difference that a6 is not the exact size I want)

Code: Select all

convert in.png  -density 300 -resize 100% -page a6  out.pdf
but can't manage to find the right set of options to make imagemagick do what I want it to.
I admit getting lost in all the options imagemagick has.

I'd be thankful for any help on getting the right command for this task.

Thanks!


Imagemagick version is

Code: Select all

Version: ImageMagick 6.9.9-38 Q16 x86_64 2018-03-12
.

Re: PNG to PDF with specific size and pixel density

Posted: 2018-12-11T11:55:38-07:00
by snibgo
monpantalon wrote:111 x 154 millimeters and >= 300dpi
111/25.4*300 = 1311 pixels
154/25.4*300 = 1819 pixels
So resize to 1311x1819, set the density, and write the file.
monpantalon wrote:with no smoothing, i.e. visible pixels.
I'm unsure what you want. Perhaps "-scale" instead of "-resize".

Re: PNG to PDF with specific size and pixel density

Posted: 2018-12-11T12:21:15-07:00
by monpantalon
OK,

Code: Select all

    convert $i -scale 1311x1819 -units PixelsPerInch -density 300x300 $i.pdf
seems to do the job!
Thanks for your help, snibgo!
By the way, the generated pdf seems a bit fuzzy when zoomed in, would setting the dpi to something making for a rounder division help?

Re: [solved] PNG to PDF with specific size and pixel density

Posted: 2018-12-11T14:08:26-07:00
by snibgo
You enlarge by a factor of ten or so. But this doesn't create new detail, so it will look fuzzy.

Re: [solved] PNG to PDF with specific size and pixel density

Posted: 2018-12-12T11:45:01-07:00
by monpantalon
Makes sense; changing the unit to PixelsPerCentimenter also works, since I get a cleaner fraction.
Thanks again!