PHP pdf 转 图片
2021-04-14 19:26
标签:扩展 pat form setimage int filename tco exists 二维数组 注意:++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 先安装 imagick 扩展 PHP pdf 转 图片 标签:扩展 pat form setimage int filename tco exists 二维数组 原文地址:https://www.cnblogs.com/5aiQ/p/12373484.htmlfunction pdf2png($pdf,$path,$page=-1)
{
if(!extension_loaded(‘imagick‘))
{
return false;
}
if(!file_exists($pdf))
{
return false;
}
if(!is_readable($pdf))
{
return false;
}
$im = new \Imagick();
$im->setResolution(150,150);
$im->setCompressionQuality(100);
// print_r($pdf);die;
if($page==-1)
$im->readImage($pdf);
else
$im->readImage($pdf."[".$page."]");
foreach ($im as $Key => $Var)
{
$Var->setImageFormat(‘png‘);
$filename = $path. md5($Key.time()).‘.png‘;
if($Var->writeImage($filename) == true)
{
$Return[] = $filename;
}
}
//返回转化图片数组,由于pdf可能多页,此处返回二维数组。
return $Return;
}