Quality issue with converting a PNG to PDF with ImageMagick in PHP

Multi tool use
Multi tool use


Quality issue with converting a PNG to PDF with ImageMagick in PHP



I have a PNG file with quite decent quality and not at all small size. I convert it to PDF like this(in php):


$imagick = new Imagick();
$imagick->readImageBlob($image);
$imagick->setImageFormat('pdf');
echo $imagick->getImageBlob();



And I get a PDF file with my image in it. But the quality gets very poor. I thought I might fix with trying different density setting it with setResolution method. But this lead to either the image becoming very small or getting even worse quality. What am I doing wrong?


setResolution





Imagick uses Imagemagick which is not a vector processor. So when convert a raster to a vector, all that will happen is that the raster image will be imbedded in a vector shell. You cannot improve the quality from that of the original raster image. So there is really no point in converting it to PDF. If that does not explain it, then please post links to your PNG and PDF images.
– fmw42
Jul 2 at 18:13





@fmw42 What I expect is simply a PDF wrapper file with a PNG image put inside as in a container. I expected it to be almost the same quality but instead I get a lot worse quality.
– Gherman
Jul 2 at 18:54





Please post links to your PNG and PDF images.
– fmw42
Jul 2 at 18:55






The echo $image->getImageBlob(); will default to a resolution of 72. How are you implementing setResolution?
– emcconville
Jul 2 at 20:57


echo $image->getImageBlob();


setResolution





@emcconville It's an implemented method in Imagick and I believe it's like denisity under the hood. $image->setResolution(300, 300);
– Gherman
Jul 2 at 21:18


Imagick


denisity


$image->setResolution(300, 300);









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

46iDx4uMk8hcXD83OSmtcy9c UQN0E8F4qfEKeq9
CTO6CcAnGrtQIy1qGwcZEO,3KErA4nv 5AcUp 3T7Vrb 0h6tk3zNDORhEQY8gMYjDI4dxrR VbJLW5QmffH

Popular posts from this blog

PHP contact form sending but not receiving emails

Do graphics cards have individual ID by which single devices can be distinguished?

Create weekly swift ios local notifications