lippoliv
lippoliv

Reputation: 727

imagemagick pdf to jpg - font quality bad

I do upload PDFs to PHP and extract the pages as JPG in different resolutions in a kind of batch through JS + AJAX-Calls to work arround PHP timeout.

But the font is rendering not so pretty... what can I do?

$pdf = new Imagick();
$pdf->setresolution(225, 225);
$pdf->readimage('mypdf[0-5]');
$written = $pdf->writeimages('previewfolder/pages/hq-0.jpg', FALSE);
$pdf->clear();
$pdf->destroy();

I tryed upsetting the values of setresolution to 500and 500, then the font is a Little bit better but the Image is also much bigger in Resolution. Here an screenshot: https://i.sstatic.net/Ei9rl.jpg

My Target: small Image (1000px*1000px) but with as max font-quality as possible.

Hopefully someone has an Idea.

Regards, lippoliv

Upvotes: 1

Views: 2073

Answers (1)

lippoliv
lippoliv

Reputation: 727

as often: mistake 40 (the mistakes sits 40cm in front of his Monitor)...

$pdf = new Imagick();
$pdf->setresolution(350, 350);
$pdf->readimage('mypdf[0-5]');

// Because we have multiple pages, we have to process each page.
foreach ($pdf as $page) {
    $page->resizeimage(1500, 1500, \Imagick::FILTER_UNDEFINED, 1.1, TRUE);
}

$written = $pdf->writeimages('previewfolder/pages/hq-0.jpg', FALSE);
$pdf->clear();
$pdf->destroy();

Thanks to Mark Setchell who brought in that Idea and made me thinking about why the resize doesn't work. And than ofter another hour of Google I found an example about resizeing Images, pointing out that you have to resize each Frame.

So I thought may I have to resize each single page of my PDF (in that example there are 6 pages) and now it works: https://i.sstatic.net/6DH3J.jpg

Now I can up- / downscale the Image size as I like to and get nice Fonts :) Even as a JPG.

Thank you all.

Upvotes: 1

Related Questions