Convert PDF to PNG without quality in PHP

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
jota_sp_84
Posts: 3
Joined: 2012-05-11T06:51:02-07:00
Authentication code: 13

Convert PDF to PNG without quality in PHP

Post by jota_sp_84 »

Hello people,

I need a help.
I'm using CentOS 6.4 with ImageMagick 6.5.4-7 Q16 and image module 2.2.2 with php 5.3.3 with Ghostscript 8.70-11.e16_2.6.

What is happening is the following. I want to convert a page of the PDF to PNG, only to be coming with bad quality! How can I fix this problem to come with perfect quality?

The code is:

<?
$im = new Imagick ();

$im->readImage ( 'file.pdf[0]' );

$im->setImageFormat('png');

header("Content-type: image/png");

echo $im;

?>

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

Re: Convert PDF to PNG without quality in PHP

Post by fmw42 »

In command line mode, you would use "supersampling". That is set the density high before reading the image and then resize back down by the same factor. For example

convert -density 288 image.pdf[0] -resize 25% image.png

normal density is 72 dpi. so 4*72=288. Thus you must resize by 1/4=25%

Sorry I don't know the equivalent in Imagick.
isswal
Posts: 1
Joined: 2012-11-12T08:22:08-07:00
Authentication code: 67790

Re: Convert PDF to PNG without quality in PHP

Post by isswal »

Hi,
can you tell me is that you settle your problem, because I have the same concern that I convert a pdf image but unfortunately the image is not good quality.

thank you very much
mkoppanen
Posts: 309
Joined: 2007-06-09T07:06:32-07:00

Re: Convert PDF to PNG without quality in PHP

Post by mkoppanen »

Mikko Koppanen
My blog: http://valokuva.org
Post Reply