0

I'm trying to convert a pdf to an image file (png, jpg, gif does not matter).

But using the following code:

<?php
$im = new imagick('helloworld.pdf[0]');
$im->setImageFormat('png');
header('Content-Type: image/png');
echo $im;
?>

Picture quality is degraded significantly.

Is there any way to convert it with no or very little quality loss ?

  • possible duplicate of [PHP+Imagick - PNG Compression](http://stackoverflow.com/questions/7462827/phpimagick-png-compression) – JimL Jul 27 '13 at 13:51
  • possible duplicate of [Convert multipage PDF to PNG and back (Linux)](http://stackoverflow.com/questions/9710118/convert-multipage-pdf-to-png-and-back-linux) – hjpotter92 Jul 27 '13 at 14:00

1 Answers1

-1

you have to play with Imagick::setCompression, Imagick::setCompressionQuality and Imagick::setImageCompression

for this guy helped

$im->setImageCompression(\Imagick::COMPRESSION_UNDEFINED); 
$im->setImageCompressionQuality(0);

anyway, you have to put some of this strings before you format the image to png

Community
  • 1
  • 1
vladkras
  • 16,483
  • 4
  • 45
  • 55
  • If you find the solution on a similar question on [so], instead of copying it, flag the questions as [duplicates](http://meta.stackexchange.com/q/10841/212576). – hjpotter92 Jul 27 '13 at 14:14
  • @hjpotter92 no, I didn't, it's just an example how someone else used these functions. Note, that answer I linked to was not a solution – vladkras Jul 27 '13 at 14:43
  • @hjpotter92 also, note, that another answer in [that](http://stackoverflow.com/a/12054887/1713660) tred ([Convert multipage PDF to PNG and back (Linux)](http://stackoverflow.com/questions/9710118/convert-multipage-pdf-to-png-and-back-linux/12046542#12046542)) points to stackoverflow again but it wasn't downvoted, because it could be helpfull (just think about this) – vladkras Jul 27 '13 at 14:50
  • Well, no change. Here is a demo of what my code is producing: http://goo.gl/wW8S2L With the code: `setImageCompression(Imagick::COMPRESSION_UNDEFINED); $im->setImageCompressionQuality(5); $im->setImageFormat('png'); header('Content-Type: image/png'); echo $im; ?>` Original pdf: http://goo.gl/l2C8tM – Patrik BoXon Nicklasson Jul 27 '13 at 16:24