php Imagick 求助, 如何使用Imagick裁切图片

WBOY
Release: 2016-06-23 14:39:57
Original
971 people have browsed it

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

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

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


回复讨论(解决方案)

$myurl = '/pdf/mypdf.pdf';$image = new Imagick(realpath($myurl).'[0]'); //[0] indicate the number of the wanted page$image->setResolution( 300, 300 );$image->setImageFormat( "png" );$image->writeImage(realpath('./mypdf.png'));
Copy after login

已经解决了还是谢谢你

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