![](/img/trans.png)
[英]How would you create a thumbnail of the first page of a pdf using php but not using ghostwrite and imagemagick
[英]Imagemagick - create a thumbnail of the first page of a PDF - PHP
我想使用imageMagick為第一頁創建在線PDF的縮略圖。 問題是我得到一個縮略圖但不是文檔的第一頁,或者我可以生成它但不是我想要的大小,即200px寬。
這是下面的代碼。
<?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);
嘗試在鏈接中添加[0]; 這在Imagemagick本地工作,但我不確定Imagick和在線。
$link1 = "http://www.flar.net/uploads/default/calendar/99f3a2304c1754aecffab145a5c80b98.pdf";
$link1 .= '[0]';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.