Use Imagick in PHP to read pdf and generate png thumbnail example, imagickpng
Generate png homepage thumbnail from pdf (the server needs to support Imagick)
Copy code The code is as follows:
/**
* PDF2PNG
* @param $pdf PDF file to be processed
* @param $path The path of the image to be saved
* @param $page The page to be exported -1 is all, 0 is the first page, 1 is the second page
* @return The path and file name of the saved image
*/
function pdf2png($pdf,$path,$page=0)
{
if(!is_dir($path))
{
mkdir($path,true);
}
if(!extension_loaded('imagick'))
{
echo 'imagick not found! ' ;
Return false;
}
if(!file_exists($pdf))
{
echo 'pdf not found' ;
return false;
}
$im = new Imagick();
$im->setResolution(120,120); //Set image resolution
$im->setCompressionQuality(80); //Compression ratio
$im->readImage($pdf."[".$page."]"); //Set the first page to read pdf
//$im->thumbnailImage(200, 100, true); //Change the size of the image
$im->scaleImage(200,100,true); //Scale the image
$filename = $path."/". time().'.png';
if($im->writeImage($filename) == true)
{
$Return = $filename;
}
Return $Return;
}
$s=pdf2png('file/1371273225-ceshi_ppt.pdf','images');
echo "
";
http://www.bkjia.com/PHPjc/945707.html
www.bkjia.com
truehttp: //www.bkjia.com/PHPjc/945707.htmlTechArticleImagick is used in PHP to read pdf and generate png thumbnail examples, imagickpng pdf generates png homepage thumbnails (server required Support Imagick) Copy the code code as follows: /** * PDF2PNG * @para...