Home > Backend Development > PHP Tutorial > php Imagick , 怎么使用Imagick裁切图片

php Imagick , 怎么使用Imagick裁切图片

WBOY
Release: 2016-06-13 11:43:18
Original
1326 people have browsed it

php Imagick 求助, 如何使用Imagick裁切图片
我需要 景某个PDF文档中的某一页裁切其中一部分, 生成一新的png格式的文档.
gd不支持PDF格式,  Imagick 支持打开pdf, 并将其中一页转成PNG, 但是如何将此页的一部分裁切出来呢

参考代码来自网络
代码如下

<br /> function pdf2png($pdf,$path,$page=-1)<br />{  <br />   if(!extension_loaded('imagick'))<br />   {  <br />       return false;  <br />   }  <br />   if(!file_exists($pdf))<br />   {  <br />       return false;  <br />   }  <br />   $im = new Imagick();  <br />   $im->setResolution(600,600);  <br />   $im->setCompressionQuality(100);<br />   if($page==-1)   <br />      $im->readImage($pdf);<br />   else<br />      $im->readImage($pdf."[".$page."]");<br />   foreach ($im as $Key => $Var)<br />   {  <br />       $height=$Var->getImageHeight();//取得原图的高度<br />       $width=$Var->getImagewidth();//取得原图的宽度<br />       //echo "H".$height."w:". $width;<br />       $im_cut = new Imagick();  //这里设置新图的实例<br />       $im_cut->setResolution(600,600); //分辨率<br />       $im_cut->setCompressionQuality(100);//压缩率<br />//       $im_cut->setImageFormat('png'); //设置新图的格式 这里出错<br />//       $im_cut->setImageType (0);<br />//       $im_cut->      接下来不知道如何做了 <br />//如何设置新图的高度长度 <br />//如何把 $var中的一部分复制到新图,<br />//如何保存新图<br /><br />       <br />       $Var->setImageFormat('png');  <br />       $Var->setImageType (0);<br />       $filename = $path."/". md5($Key.time()).'.png';<br />       if($Var->writeImage($filename) == true)<br />       {  <br />           $Return[] = $filename;  <br />       }  <br />   }  <br />   return $Return;  <br />}  <br />
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template