[英]Imagemagick - create a thumbnail of the first page of a PDF - PHP
I would like to create a thumbnail of an online PDF for the first page using imageMagick. 我想使用imageMagick为第一页创建在线PDF的缩略图。 The problem is I do get a thumbnail but not for the first page of the document, or I can generate it but not for the size that I want, ie 200px wide. 问题是我得到一个缩略图但不是文档的第一页,或者我可以生成它但不是我想要的大小,即200px宽。
Here is the code below. 这是下面的代码。
<?php
function createOnlineDocumentThumbnail2($index, $output, $path)
{
$pdf = new \Imagick($path);
$pdf->setIteratorIndex($index);
$pdf->setResolution(320, 320);
//$pdf = $pdf->flattenImages();
$pdf->setBackgroundColor('white');
//$pdf->thumbnailImage(200, 0);
$pdf->setImageColorspace(255);
$pdf->setCompression(\Imagick::COMPRESSION_JPEG);
$pdf->setCompressionQuality(100);
$pdf->setImageFormat('jpeg');
$pdf->writeImage($output);
$pdf->clear();
$pdf->destroy();
}
function createOnlineDocumentThumbnail($index, $output, $path)
{
$pdf = new \Imagick($path);
$pdf->setIteratorIndex($index);
$pdf->setResolution(320, 320);
$pdf = $pdf->flattenImages();
$pdf->setBackgroundColor('white');
$pdf->thumbnailImage(200, 0);
$pdf->setImageColorspace(255);
$pdf->setCompression(\Imagick::COMPRESSION_JPEG);
$pdf->setCompressionQuality(100);
$pdf->setImageFormat('jpeg');
$pdf->writeImage($output);
$pdf->clear();
$pdf->destroy();
}
$link1 = "http://www.flar.net/uploads/default/calendar/99f3a2304c1754aecffab145a5c80b98.pdf";
$link2 = "http://www.pdf995.com/samples/pdf.pdf";
createOnlineDocumentThumbnail2(0, 'output/link1.jpg', $link1);
createOnlineDocumentThumbnail2(0, 'output/link2.jpg', $link2);
createOnlineDocumentThumbnail(0, 'output/link1_small.jpg', $link1);
createOnlineDocumentThumbnail(0, 'output/link2_small.jpg', $link2);
Try adding a [0] to your link; 尝试在链接中添加[0]; this works locally on Imagemagick but I am not sure about Imagick and online. 这在Imagemagick本地工作,但我不确定Imagick和在线。
$link1 = "http://www.flar.net/uploads/default/calendar/99f3a2304c1754aecffab145a5c80b98.pdf";
$link1 .= '[0]';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.