[resolved, thanks!] loss of resolution converting PDF to PNG

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
traq
Posts: 5
Joined: 2014-05-02T10:18:26-07:00
Authentication code: 6789

[resolved, thanks!] loss of resolution converting PDF to PNG

Post by traq »

I have a PDF which I am trying to convert to PNG. The PDF is 35.46" × 17.24" at 400dpi, but when I convert to PNG, the output image is only 2553px × 1241px (I'm expecting more like 14184×6896).
I was able to use the -resize option to get the expected dimensions, but it is just an enlarged version of the smaller converted image.

Comparison (original PDF on the left; converted (enlarged) PNG on the right):
Image

I'm a fairly new ImageMagick user, so I'm sure this is just something I'm not specifying correctly. I'm using version 6.7.7-10 2013-02-25 Q16 from the cli on Linux Mint.

Some commands I've tried so far:

Code: Select all

convert -colors 540000 <pdf file name> <png file name>
convert -colors 540000 -size 14184x6896 <pdf file name> <png file name>
convert <pdf file name> -colors 540000 -size 14184x6896 <png file name>
convert <pdf file name> -colors 540000 -resize 14184x6896 <png file name>
Any ideas?
Last edited by traq on 2014-05-02T11:55:27-07:00, edited 2 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: severe loss of resolution converting from PDF to PNG

Post by snibgo »

traq wrote:The PDF is 35.46" × 17.24" at 400dpi ...
You need to tell ImageMagick this, with "-density 400". (Not with "-size".)
snibgo's IM pages: im.snibgo.com
traq
Posts: 5
Joined: 2014-05-02T10:18:26-07:00
Authentication code: 6789

Re: severe loss of resolution converting from PDF to PNG

Post by traq »

snibgo wrote:
traq wrote:The PDF is 35.46" × 17.24" at 400dpi ...
You need to tell ImageMagick this, with "-density 400". (Not with "-size".)
So,

Code: Select all

convert <pdf file name> -colors 540000 -density 400 <png file name>
?
(I am trying this out for myself; I just wanted to double-check since it's been taking about an hour for IM to finish.)

Thanks!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: severe loss of resolution converting from PDF to PNG

Post by snibgo »

"-density" tells Ghostscript what resolution to use, so it needs to come before the pdf file name.
snibgo's IM pages: im.snibgo.com
traq
Posts: 5
Joined: 2014-05-02T10:18:26-07:00
Authentication code: 6789

Re: severe loss of resolution converting from PDF to PNG

Post by traq »

alright, thanks!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: severe loss of resolution converting from PDF to PNG

Post by fmw42 »

You can also specify a larger density than 400 and then resize the image down to the right size. That will give higher quality but will take longer to process.
traq
Posts: 5
Joined: 2014-05-02T10:18:26-07:00
Authentication code: 6789

Re: severe loss of resolution converting from PDF to PNG

Post by traq »

fmw42 wrote:You can also specify a larger density than 400 and then resize the image down to the right size. That will give higher quality …
Even though the original is only 400dpi?

edit: the -density option worked perfectly. Thanks so much!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [resolved, thanks!] loss of resolution converting PDF to

Post by fmw42 »

you could do

Code: Select all

convert -density 800 image.pdf -resize 50% image.png
That would make the intermediate image twice the dimensions you need, but then resize it down by 50% to the size you wanted. This is not need, but just an option.

or

Code: Select all

convert -density XX image.pdf -resize 14184×6896 image.png
where XX is >400
traq
Posts: 5
Joined: 2014-05-02T10:18:26-07:00
Authentication code: 6789

Re: [resolved, thanks!] loss of resolution converting PDF to

Post by traq »

fmw42 wrote:

Code: Select all

convert -density 800 image.pdf -resize 50% image.png
That would make the intermediate image twice the dimensions you need, but then resize it down by 50% to the size you wanted. This is not need, but just an option.
Got it. I was just wondering if doing that would give any benefit, seeing as the original is only 400dpi…?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [resolved, thanks!] loss of resolution converting PDF to

Post by fmw42 »

It might give slightly better quality. But you should test and make that determination.
Post Reply