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

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
monpantalon
Posts: 3
Joined: 2018-12-11T11:14:02-07:00
Authentication code: 1152

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

Post 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
.
Last edited by monpantalon on 2018-12-11T12:21:35-07:00, edited 1 time in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: PNG to PDF with specific size and pixel density

Post 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".
snibgo's IM pages: im.snibgo.com
monpantalon
Posts: 3
Joined: 2018-12-11T11:14:02-07:00
Authentication code: 1152

Re: PNG to PDF with specific size and pixel density

Post 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?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post by snibgo »

You enlarge by a factor of ten or so. But this doesn't create new detail, so it will look fuzzy.
snibgo's IM pages: im.snibgo.com
monpantalon
Posts: 3
Joined: 2018-12-11T11:14:02-07:00
Authentication code: 1152

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

Post by monpantalon »

Makes sense; changing the unit to PixelsPerCentimenter also works, since I get a cleaner fraction.
Thanks again!
Post Reply