PDF to JPG – Trying to obtain a “Crisp” (not fuzzy) JPG

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
BradM
Posts: 8
Joined: 2012-05-29T16:56:27-07:00
Authentication code: 13

PDF to JPG – Trying to obtain a “Crisp” (not fuzzy) JPG

Post by BradM » 2012-08-05T11:15:10-07:00

All,

I am trying to convert a PDF file to a JPG file.

The conversion is working, but the generated JPG image is quite fuzzy.

I am using a “-quality 100” parameter.

Are there other ImageMagick parameters that I should be using to eliminate the fuzziness?

Thanks,
Brad

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

Re: PDF to JPG – Trying to obtain a “Crisp” (not fuzzy) JPG

Post by fmw42 » 2012-08-05T11:30:58-07:00

use supersampling

convert -density 288 image.pdf -resize 25% -quality 100 image.jpg

PDF files have no real size and its size is defined by the -density. Nominal density is 72. So 288 =72*4. Thus we have to resize by 1/4 to get back to normal size afterwards. You also may not need -quality 100 if the supersampling helps. You might be able to lower the jpg quality and still be fine.

BradM
Posts: 8
Joined: 2012-05-29T16:56:27-07:00
Authentication code: 13

Re: PDF to JPG – Trying to obtain a “Crisp” (not fuzzy) JPG

Post by BradM » 2012-08-05T12:10:35-07:00

fmw42,

Thanks for the assistance. I really appreciate it.

The " -density 288" parameter did the trick.

I am all smiles.

Thanks again,

Brad

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: PDF to JPG – Trying to obtain a “Crisp” (not fuzzy) JPG

Post by henrywho » 2012-08-07T01:00:10-07:00

To add even more acutance (sth like edge sharpness),

Code: Select all

convert -density 288 image.pdf -filter lagrange -distort resize 25% -quality 95 -sampling-factor 1:1 image.jpg
Linear RGB resize is mathematically more correct but this is probably counter-productive in this use case:

Code: Select all

convert -density 288 image.pdf -colorspace RGB -filter lagrange -distort resize 25% -colorspace sRGB -quality 95 -sampling-factor 1:1 image.jpg
BTW, If your PDF contains transparency, insert " -background white -alpha remove " after the pdf file name.
Last edited by henrywho on 2012-08-07T17:05:42-07:00, edited 1 time in total.

pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: PDF to JPG – Trying to obtain a “Crisp” (not fuzzy) JPG

Post by pipitas » 2012-08-07T05:28:12-07:00

fmw42 wrote:use supersampling
convert -density 288 image.pdf -resize 25% -quality 100 image.jpg
I ran

Code: Select all

convert  -density 288  http://qtrac.eu/boson1.pdf[1]  -scale 25% boson2-supersampled.jpg
and the output is almost all black (apart from 2 spots).

If I let go the scale step, running this:

Code: Select all

convert  -density 288  http://qtrac.eu/boson1.pdf[1]  boson2-400pc.jpg
the output is OK.

Could this be a general ImageMagick bug?! Or could this come from enabling OpenCL and/or HDRI?

My IM version is:

Code: Select all

Version: ImageMagick 6.7.8-3 2012-07-30 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features:  OpenCL HDRI


Also, using PNG instead of JPEG does look better: but there are still 1 (smaller) issue with it:
  • * The output PNGs show a gray background. (The original PDF page has a transparent background).

pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

Re: PDF to JPG – Trying to obtain a “Crisp” (not fuzzy) JPG

Post by pipitas » 2012-08-07T05:34:36-07:00

pipitas wrote:
fmw42 wrote:use supersampling
convert -density 288 image.pdf -resize 25% -quality 100 image.jpg
I ran

Code: Select all

convert  -density 288  http://qtrac.eu/boson1.pdf[1]  -scale 25% boson2-supersampled.jpg
and the output is almost all black (apart from 2 spots).
Ahhh... thanks to henrywho's hint I added -background white -alpha remove behind the PDF name and then it worked as expected:

Code: Select all

convert  -density 288  http://qtrac.eu/boson1.pdf[1]  -background white  -alpha remove  -scale 25% boson2-supersampled.jpg
No more black page!

:)

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

Re: PDF to JPG – Trying to obtain a “Crisp” (not fuzzy) JPG

Post by fmw42 » 2012-08-07T10:06:43-07:00

You will get better quality though slower by using -resize rather than -scale

Post Reply