{"id":411,"date":"2015-02-14T22:54:42","date_gmt":"2015-02-14T14:54:42","guid":{"rendered":"http:\/\/www.zyuns.com\/?p=411"},"modified":"2015-02-15T20:46:33","modified_gmt":"2015-02-15T12:46:33","slug":"php%e6%89%a9%e5%b1%95imagick","status":"publish","type":"post","link":"https:\/\/www.siediyer.cn\/?p=411","title":{"rendered":"php\u6269\u5c55imagick"},"content":{"rendered":"<p>imagick\u662f\u4e00\u4e2a\u53ef\u4ee5\u4f9bPHP\u8c03\u7528ImageMagick\u529f\u80fd\u7684PHP\u6269\u5c55\u3002\u4f7f\u7528\u8fd9\u4e2a\u6269\u5c55\u53ef\u4ee5\u4f7fPHP\u5177\u5907\u548cImageMagick\u76f8\u540c\u7684\u529f\u80fd\u3002<\/p>\n<p>PHP\u5efa\u56fe\u901a\u5e38\u90fd\u7528GD\u5e93,\u56e0\u4e3a\u662f\u5185\u7f6e\u7684\u4e0d\u9700\u8981\u5728\u670d\u52a1\u5668\u4e0a\u989d\u5916\u5b89\u88c5\u63d2\u4ef6,\u6240\u4ee5\u7528\u8d77\u6765\u6bd4\u8f83\u7701\u5fc3,\u4f46\u662f\u5982\u679c\u4f60\u7684\u7a0b\u5e8f\u4e3b\u8981\u7684\u529f\u80fd\u5c31\u662f\u5904\u7406\u56fe\u50cf,\u90a3\u9ebc\u5c31\u4e0d\u5efa\u8bae\u7528GD\u4e86,\u56e0\u4e3aGD\u4e0d\u4f46\u4f4e\u6548\u80fd\u800c\u4e14\u80fd\u529b\u4e5f\u6bd4\u8f83\u5f31,\u4f54\u7528\u7684\u7cfb\u7edf\u8d44\u6e90\u4e5f\u9887\u591a,\u53e6\u5916GD\u7684creatfrom\u4e5f\u6709bug,\u800cimagick\u5374\u662f\u4e00\u4e2a\u5f88\u597d\u7684\u66ff\u4ee3\u54c1,\u4e3a\u6b64\u6700\u8fd1\u628a\u6211\u7684\u4e00\u4e2a\u9879\u76ee\u7531GD\u6539\u6210\u4e86imagick,\u4f46\u662f\u6539\u5b8c\u4e4b\u540e\u51fa\u73b0\u4e86\u4e00\u4e9b\u72b6\u51b5\u5728\u6b64\u5206\u4eab\u7ed9\u5927\u5bb6.<\/p>\n<p>\u9996\u5148\u8bf4\u4e00\u4e0b\u6211\u8fd9\u8fb9\u51fa\u73b0\u7684\u72b6\u51b5:<\/p>\n<p>\u72b6\u51b5\u4e00:\u9700\u8981\u91cd\u5199\u56fe\u50cf\u64cd\u4f5cclass<\/p>\n<p>\u72b6\u51b5\u4e8c:imagick\u591a\u7ebf\u7a0b\u65f6\u4f1a\u5bfc\u81f4cpu\u4f7f\u7528\u7387\u66b4\u589e\u5230100%<\/p>\n<p>\u5728\u6b64\u987a\u4fbf\u63d0\u4e00\u4e0bimagick\u5728centos6.4\u7684\u5b89\u88c5\u65b9\u6cd5:<\/p>\n<p>1\u3001\u5b89\u88c5ImageMagick<\/p>\n<p>wget http:\/\/soft.vpser.net\/web\/imagemagick\/ImageMagick-6.7.1-2.tar.gz<br \/>\ntar zxvf ImageMagick-6.7.1-2.tar.gz<br \/>\ncd ImageMagick-6.7.1-2\/<br \/>\n.\/configure &#8211;prefix=\/usr\/local\/imagemagick &#8211;disable-openmp<br \/>\nmake &amp;&amp; make install<br \/>\nldconfig<\/p>\n<p>\u6d4b\u8bd5ImageMagick\u662f\u5426\u53ef\u4ee5\u6b63\u5e38\u8fd0\u884c\uff1a<\/p>\n<p>\/usr\/local\/imagemagick\/bin\/convert -version<\/p>\n<p>2\u3001\u5b89\u88c5PHP\u6269\u5c55\uff1aimagick<\/p>\n<p>wget http:\/\/pecl.php.net\/get\/imagick-3.0.1.tgz<br \/>\ntar zxvf imagick-3.0.1.tgz<br \/>\ncd imagick-3.0.1\/<br \/>\n\/usr\/local\/php\/bin\/phpize<br \/>\n.\/configure &#8211;with-php-config=\/usr\/local\/php\/bin\/php-config &#8211;with-imagick=\/usr\/local\/imagemagick<br \/>\nmake &amp;&amp; make install<br \/>\nldconfig<br \/>\nvi \/usr\/local\/php\/etc\/php.ini<br \/>\n\u6dfb\u52a0\uff1aextension = &#8220;imagick.so&#8221;<\/p>\n<p>\u91cd\u542flnmp<\/p>\n<p>\/root\/lnmp reload<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u9488\u5bf9\u4e0a\u8ff0\u4e24\u4e2a\u72b6\u51b5\u5206\u522b\u63d0\u51fa\u89e3\u51b3\u529e\u6cd5:<\/p>\n<p>\u72b6\u51b5\u4e00\u7684\u89e3\u51b3\u529e\u6cd5\u5982\u4e0b:<br \/>\n\/**<br \/>\nImagick\u56fe\u50cf\u5904\u7406\u7c7b<br \/>\n\u7528\u6cd5:<br \/>\n\/\/\u5f15\u5165Imagick\u7269\u4ef6<br \/>\nif(!defined(&#8216;CLASS_IMAGICK&#8217;)){require(Inc.&#8217;class_imagick.php&#8217;);}<br \/>\n$Imagick=new class_imagick();<br \/>\n$Imagick-&gt;open(&#8216;a.gif&#8217;);<br \/>\n$Imagick-&gt;resize_to(100,100,&#8217;scale_fill&#8217;);<br \/>\n$Imagick-&gt;add_text(&#8216;1024i.com&#8217;,10,20);<br \/>\n$Imagick-&gt;add_watermark(&#8216;1024i.gif&#8217;,10,50);<br \/>\n$Imagick-&gt;save_to(&#8216;x.gif&#8217;);<br \/>\nunset($Imagick);<br \/>\n\/**\/<br \/>\ndefine(&#8216;CLASS_IMAGICK&#8217;,TRUE);<br \/>\nclass class_imagick{<br \/>\nprivate $image=null;<br \/>\nprivate $type=null;<br \/>\n\/\/ \u6784\u9020<br \/>\npublic function __construct(){}<br \/>\n\/\/ \u6790\u6784<br \/>\npublic function __destruct(){<br \/>\nif($this-&gt;image!==null){$this-&gt;image-&gt;destroy();}<br \/>\n}<br \/>\n\/\/ \u8f7d\u5165\u56fe\u50cf<br \/>\npublic function open($path){<br \/>\nif(!file_exists($path)){<br \/>\n$this-&gt;image=null;<br \/>\nreturn ;<br \/>\n}<br \/>\n$this-&gt;image=new Imagick($path);<br \/>\nif($this-&gt;image){<br \/>\n$this-&gt;type=strtolower($this-&gt;image-&gt;getImageFormat());<br \/>\n}<br \/>\n$this-&gt;image-&gt;stripImage();<br \/>\nreturn $this-&gt;image;<br \/>\n}<br \/>\n\/**<br \/>\n\u56fe\u50cf\u88c1\u5207<br \/>\n\/**\/<br \/>\npublic function crop($x=0,$y=0,$width=null,$height=null){<br \/>\nif($width==null) $width=$this-&gt;image-&gt;getImageWidth()-$x;<br \/>\nif($height==null) $height=$this-&gt;image-&gt;getImageHeight()-$y;<br \/>\nif($width&lt;=0 || $height&lt;=0) return;<br \/>\nif($this-&gt;type==&#8217;gif&#8217;){<br \/>\n$image=$this-&gt;image;<br \/>\n$canvas=new Imagick();<br \/>\n$images=$image-&gt;coalesceImages();<br \/>\nforeach($images as $frame){<br \/>\n$img=new Imagick();<br \/>\n$img-&gt;readImageBlob($frame);<br \/>\n$img-&gt;cropImage($width,$height,$x,$y);<br \/>\n$canvas-&gt;addImage($img);<br \/>\n$canvas-&gt;setImageDelay($img-&gt;getImageDelay());<br \/>\n$canvas-&gt;setImagePage($width,$height,0,0);<br \/>\n}<br \/>\n$image-&gt;destroy();<br \/>\n$this-&gt;image=$canvas;<br \/>\n}else{<br \/>\n$this-&gt;image-&gt;cropImage($width,$height,$x,$y);<br \/>\n}<br \/>\n}<br \/>\n\/**<br \/>\n\u66f4\u6539\u56fe\u50cf\u5927\u5c0f<br \/>\n\u53c2\u6570:<br \/>\n$width:\u65b0\u7684\u5bbd\u5ea6<br \/>\n$height:\u65b0\u7684\u9ad8\u5ea6<br \/>\n$fit: \u9002\u5e94\u5927\u5c0f<br \/>\n&#8216;force&#8217;: \u628a\u56fe\u50cf\u5f3a\u5236\u6539\u4e3a$width X $height<br \/>\n&#8216;scale&#8217;: \u6309\u6bd4\u4f8b\u5728$width X $height\u5185\u7f29\u653e\u56fe\u7247,\u7ed3\u679c\u4e0d\u5b8c\u5168\u7b49\u65bc$width X $height<br \/>\n&#8216;scale_fill&#8217;:\u6309\u6bd4\u4f8b\u5728$width X $height\u5185\u7f29\u653e\u56fe\u7247,\u6ca1\u6709\u50cf\u7d20\u7684\u5730\u65b9\u586b\u5145\u984f\u8272$fill_color=array(255,255,255)(\u7ea2,\u7eff,\u84dd,\u900f\u660e\u5ea6[0\u4e0d\u900f\u660e-127\u5168\u900f\u660e])<br \/>\n\u5176\u4ed6:\u667a\u80fd\u6a21\u5f0f,\u7f29\u653e\u56fe\u7247\u5e76\u4ece\u6b63\u4e2d\u88c1\u5207$width X $height\u7684\u5927\u5c0f<br \/>\n\u6ce8\u610f:<br \/>\n$fit=&#8217;force&#8217;,&#8217;scale&#8217;,&#8217;scale_fill&#8217;\u65f6\u8f93\u51fa\u5b8c\u6574\u56fe\u50cf<br \/>\n$fit=\u56fe\u50cf\u65b9\u4f4d\u65f6\u8f93\u51fa\u6307\u5b9a\u4f4d\u7f6e\u90e8\u4efd\u7684\u56fe\u50cf<br \/>\n\u5b57\u6bcd\u4e0e\u56fe\u50cf\u7684\u5bf9\u5e94\u5173\u7cfb\u5982\u4e0b:<br \/>\nnorth_west\u00a0\u00a0 north\u00a0\u00a0 north_east<br \/>\nwest\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 center\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 east<br \/>\nsouth_west\u00a0\u00a0 south\u00a0\u00a0 south_east<br \/>\n\/**\/<br \/>\npublic function resize_to($width=100,$height=100,$fit=&#8217;center&#8217;,$fill_color=array(255,255,255,0)){<br \/>\nswitch($fit){<br \/>\ncase &#8216;force&#8217;:<br \/>\nif($this-&gt;type==&#8217;gif&#8217;){<br \/>\n$image=$this-&gt;image;<br \/>\n$canvas=new Imagick();<br \/>\n$images=$image-&gt;coalesceImages();<br \/>\nforeach($images as $frame){<br \/>\n$img=new Imagick();<br \/>\n$img-&gt;readImageBlob($frame);<br \/>\n$img-&gt;thumbnailImage($width,$height,false);<br \/>\n$canvas-&gt;addImage($img);<br \/>\n$canvas-&gt;setImageDelay($img-&gt;getImageDelay());<br \/>\n}<br \/>\n$image-&gt;destroy();<br \/>\n$this-&gt;image=$canvas;<br \/>\n}else{<br \/>\n$this-&gt;image-&gt;thumbnailImage($width,$height,false);<br \/>\n}<br \/>\nbreak;<br \/>\ncase &#8216;scale&#8217;:<br \/>\nif($this-&gt;type==&#8217;gif&#8217;){<br \/>\n$image=$this-&gt;image;<br \/>\n$images=$image-&gt;coalesceImages();<br \/>\n$canvas=new Imagick();<br \/>\nforeach($images as $frame){<br \/>\n$img=new Imagick();<br \/>\n$img-&gt;readImageBlob($frame);<br \/>\n$img-&gt;thumbnailImage($width,$height,true);<br \/>\n$canvas-&gt;addImage($img);<br \/>\n$canvas-&gt;setImageDelay($img-&gt;getImageDelay());<br \/>\n}<br \/>\n$image-&gt;destroy();<br \/>\n$this-&gt;image=$canvas;<br \/>\n}else{<br \/>\n$this-&gt;image-&gt;thumbnailImage($width,$height,true);<br \/>\n}<br \/>\nbreak;<br \/>\ncase &#8216;scale_fill&#8217;:<br \/>\n$size=$this-&gt;image-&gt;getImagePage();<br \/>\n$src_width=$size[&#8216;width&#8217;];<br \/>\n$src_height=$size[&#8216;height&#8217;];<br \/>\n$x=0;<br \/>\n$y=0;<br \/>\n$dst_width=$width;<br \/>\n$dst_height=$height;<br \/>\nif($src_width*$height &gt; $src_height*$width){<br \/>\n$dst_height=intval($width*$src_height\/$src_width);<br \/>\n$y=intval(($height-$dst_height)\/2);<br \/>\n}else{<br \/>\n$dst_width=intval($height*$src_width\/$src_height);<br \/>\n$x=intval(($width-$dst_width)\/2);<br \/>\n}<br \/>\n$image=$this-&gt;image;<br \/>\n$canvas=new Imagick();<br \/>\n$color=&#8217;rgba(&#8216;.$fill_color[0].&#8217;,&#8217;.$fill_color[1].&#8217;,&#8217;.$fill_color[2].&#8217;,&#8217;.$fill_color[3].&#8217;)&#8217;;<br \/>\nif($this-&gt;type==&#8217;gif&#8217;){<br \/>\n$images=$image-&gt;coalesceImages();<br \/>\nforeach($images as $frame){<br \/>\n$frame-&gt;thumbnailImage($width,$height,true);<br \/>\n$draw=new ImagickDraw();<br \/>\n$draw-&gt;composite($frame-&gt;getImageCompose(),$x,$y,$dst_width,$dst_height,$frame);<br \/>\n$img=new Imagick();<br \/>\n$img-&gt;newImage($width,$height,$color,&#8217;gif&#8217;);<br \/>\n$img-&gt;drawImage($draw);<br \/>\n$canvas-&gt;addImage($img);<br \/>\n$canvas-&gt;setImageDelay($img-&gt;getImageDelay());<br \/>\n$canvas-&gt;setImagePage($width,$height,0,0);<br \/>\n}<br \/>\n}else{<br \/>\n$image-&gt;thumbnailImage($width,$height,true);<br \/>\n$draw=new ImagickDraw();<br \/>\n$draw-&gt;composite($image-&gt;getImageCompose(),$x,$y,$dst_width,$dst_height,$image);<br \/>\n$canvas-&gt;newImage($width,$height,$color,$this-&gt;get_type());<br \/>\n$canvas-&gt;drawImage($draw);<br \/>\n$canvas-&gt;setImagePage($width,$height,0,0);<br \/>\n}<br \/>\n$image-&gt;destroy();<br \/>\n$this-&gt;image=$canvas;<br \/>\nbreak;<br \/>\ndefault:<br \/>\n$size=$this-&gt;image-&gt;getImagePage();<br \/>\n$src_width=$size[&#8216;width&#8217;];<br \/>\n$src_height=$size[&#8216;height&#8217;];<br \/>\n$crop_x=0;<br \/>\n$crop_y=0;<br \/>\n$crop_w=$src_width;<br \/>\n$crop_h=$src_height;<br \/>\nif($src_width*$height &gt; $src_height*$width){<br \/>\n$crop_w=intval($src_height*$width\/$height);<br \/>\n}else{<br \/>\n$crop_h=intval($src_width*$height\/$width);<br \/>\n}<br \/>\nswitch($fit){<br \/>\ncase &#8216;north_west&#8217;:<br \/>\n$crop_x=0;<br \/>\n$crop_y=0;<br \/>\nbreak;<br \/>\ncase &#8216;north&#8217;:<br \/>\n$crop_x=intval(($src_width-$crop_w)\/2);<br \/>\n$crop_y=0;<br \/>\nbreak;<br \/>\ncase &#8216;north_east&#8217;:<br \/>\n$crop_x=$src_width-$crop_w;<br \/>\n$crop_y=0;<br \/>\nbreak;<br \/>\ncase &#8216;west&#8217;:<br \/>\n$crop_x=0;<br \/>\n$crop_y=intval(($src_height-$crop_h)\/2);<br \/>\nbreak;<br \/>\ncase &#8216;center&#8217;:<br \/>\n$crop_x=intval(($src_width-$crop_w)\/2);<br \/>\n$crop_y=intval(($src_height-$crop_h)\/2);<br \/>\nbreak;<br \/>\ncase &#8216;east&#8217;:<br \/>\n$crop_x=$src_width-$crop_w;<br \/>\n$crop_y=intval(($src_height-$crop_h)\/2);<br \/>\nbreak;<br \/>\ncase &#8216;south_west&#8217;:<br \/>\n$crop_x=0;<br \/>\n$crop_y=$src_height-$crop_h;<br \/>\nbreak;<br \/>\ncase &#8216;south&#8217;:<br \/>\n$crop_x=intval(($src_width-$crop_w)\/2);<br \/>\n$crop_y=$src_height-$crop_h;<br \/>\nbreak;<br \/>\ncase &#8216;south_east&#8217;:<br \/>\n$crop_x=$src_width-$crop_w;<br \/>\n$crop_y=$src_height-$crop_h;<br \/>\nbreak;<br \/>\ndefault:<br \/>\n$crop_x=intval(($src_width-$crop_w)\/2);<br \/>\n$crop_y=intval(($src_height-$crop_h)\/2);<br \/>\n}<br \/>\n$image=$this-&gt;image;<br \/>\n$canvas=new Imagick();<br \/>\nif($this-&gt;type==&#8217;gif&#8217;){<br \/>\n$images=$image-&gt;coalesceImages();<br \/>\nforeach($images as $frame){<br \/>\n$img=new Imagick();<br \/>\n$img-&gt;readImageBlob($frame);<br \/>\n$img-&gt;cropImage($crop_w,$crop_h,$crop_x,$crop_y);<br \/>\n$img-&gt;thumbnailImage($width,$height,true);<br \/>\n$canvas-&gt;addImage($img);<br \/>\n$canvas-&gt;setImageDelay($img-&gt;getImageDelay());<br \/>\n$canvas-&gt;setImagePage($width,$height,0,0);<br \/>\n}<br \/>\n}else{<br \/>\n$image-&gt;cropImage($crop_w,$crop_h,$crop_x,$crop_y);<br \/>\n$image-&gt;thumbnailImage($width,$height,true);<br \/>\n$canvas-&gt;addImage($image);<br \/>\n$canvas-&gt;setImagePage($width,$height,0,0);<br \/>\n}<br \/>\n$image-&gt;destroy();<br \/>\n$this-&gt;image=$canvas;<br \/>\n}<br \/>\n}<br \/>\n\/**<br \/>\n\u6dfb\u52a0\u56fe\u7247\u6c34\u5370<br \/>\n\u53c2\u6570:<br \/>\n$path:\u6c34\u5370\u56fe\u7247(\u5305\u542b\u5b8c\u6574\u8def\u5f84)<br \/>\n$x,$y:\u6c34\u5370\u5ea7\u6807<br \/>\n\/**\/<br \/>\npublic function add_watermark($path,$x=0,$y=0){<br \/>\n$watermark=new Imagick($path);<br \/>\n$draw=new ImagickDraw();<br \/>\n$draw-&gt;composite($watermark-&gt;getImageCompose(),$x,$y,$watermark-&gt;getImageWidth(),$watermark-&gt;getimageheight(),$watermark);<br \/>\nif($this-&gt;type==&#8217;gif&#8217;){<br \/>\n$image=$this-&gt;image;<br \/>\n$canvas=new Imagick();<br \/>\n$images=$image-&gt;coalesceImages();<br \/>\nforeach($image as $frame){<br \/>\n$img=new Imagick();<br \/>\n$img-&gt;readImageBlob($frame);<br \/>\n$img-&gt;drawImage($draw);<br \/>\n$canvas-&gt;addImage($img);<br \/>\n$canvas-&gt;setImageDelay($img-&gt;getImageDelay());<br \/>\n}<br \/>\n$image-&gt;destroy();<br \/>\n$this-&gt;image=$canvas;<br \/>\n}else{<br \/>\n$this-&gt;image-&gt;drawImage($draw);<br \/>\n}<br \/>\n}<br \/>\n\/**<br \/>\n\u6dfb\u52a0\u6587\u5b57\u6c34\u5370<br \/>\n\u53c2\u6570:<br \/>\n$text:\u6c34\u5370\u6587\u5b57<br \/>\n$x,$y:\u6c34\u5370\u5ea7\u6807<br \/>\n\/**\/<br \/>\npublic function add_text($text,$x=0,$y=0,$angle=0,$style=array()){<br \/>\n$draw=new ImagickDraw();<br \/>\nif(isset($style[&#8216;font&#8217;])) $draw-&gt;setFont($style[&#8216;font&#8217;]);<br \/>\nif(isset($style[&#8216;font_size&#8217;])) $draw-&gt;setFontSize($style[&#8216;font_size&#8217;]);<br \/>\nif(isset($style[&#8216;fill_color&#8217;])) $draw-&gt;setFillColor($style[&#8216;fill_color&#8217;]);<br \/>\nif(isset($style[&#8216;under_color&#8217;])) $draw-&gt;setTextUnderColor($style[&#8216;under_color&#8217;]);<br \/>\nif($this-&gt;type==&#8217;gif&#8217;){<br \/>\nforeach($this-&gt;image as $frame){<br \/>\n$frame-&gt;annotateImage($draw,$x,$y,$angle,$text);<br \/>\n}<br \/>\n}else{<br \/>\n$this-&gt;image-&gt;annotateImage($draw,$x,$y,$angle,$text);<br \/>\n}<br \/>\n}<br \/>\n\/**<br \/>\n\u56fe\u7247\u5b58\u6863<br \/>\n\u53c2\u6570:<br \/>\n$path:\u5b58\u6863\u7684\u4f4d\u7f6e\u548c\u65b0\u7684\u6863\u6848\u540d<br \/>\n\/**\/<br \/>\npublic function save_to($path){<br \/>\n$this-&gt;image-&gt;stripImage();<br \/>\nswitch($this-&gt;type){<br \/>\ncase &#8216;gif&#8217;:<br \/>\n$this-&gt;image-&gt;writeImages($path,true);<br \/>\nreturn ;<br \/>\ncase &#8216;jpg&#8217;:<br \/>\ncase &#8216;jpeg&#8217;:<br \/>\n$this-&gt;image-&gt;setImageCompressionQuality($_ENV[&#8216;ImgQ&#8217;]);<br \/>\n$this-&gt;image-&gt;writeImage($path);<br \/>\nreturn ;<br \/>\ncase &#8216;png&#8217;:<br \/>\n$flag = $this-&gt;image-&gt;getImageAlphaChannel();<br \/>\n\/\/ \u5982\u679cpng\u80cc\u666f\u4e0d\u900f\u660e\u5219\u538b\u7f29<br \/>\nif(imagick::ALPHACHANNEL_UNDEFINED == $flag or imagick::ALPHACHANNEL_DEACTIVATE == $flag){<br \/>\n$this-&gt;image-&gt;setImageType(imagick::IMGTYPE_PALETTE);<br \/>\n$this-&gt;image-&gt;writeImage($path);<br \/>\n}else{<br \/>\n$this-&gt;image-&gt;writeImage($path);<br \/>\n}unset($flag);<br \/>\nreturn ;<br \/>\ndefault:<br \/>\n$this-&gt;image-&gt;writeImage($path);<br \/>\nreturn ;<br \/>\n}<br \/>\n}<br \/>\n\/\/ \u76f4\u63a5\u8f93\u51fa\u56fe\u50cf\u5230\u8424\u5e55<br \/>\npublic function output($header=true){<br \/>\nif($header) header(&#8216;Content-type: &#8216;.$this-&gt;type);<br \/>\necho $this-&gt;image-&gt;getImagesBlob();<br \/>\n}<br \/>\n\/**<br \/>\n\u5efa\u7acb\u7f29\u5c0f\u56fe<br \/>\n$fit\u4e3a\u771f\u65f6,\u5c06\u4fdd\u6301\u6bd4\u4f8b\u5e76\u5728$width X $height\u5185\u7522\u751f\u7f29\u5c0f\u56fe<br \/>\n\/**\/<br \/>\npublic function thumbnail($width=100,$height=100,$fit=true){$this-&gt;image-&gt;thumbnailImage($width,$height,$fit);}<br \/>\n\/**<br \/>\n\u7ed9\u56fe\u50cf\u6dfb\u52a0\u8fb9\u6846<br \/>\n$width: \u5de6\u53f3\u8fb9\u6846\u5bbd\u5ea6<br \/>\n$height: \u4e0a\u4e0b\u8fb9\u6846\u5bbd\u5ea6<br \/>\n$color: \u984f\u8272<br \/>\n\/**\/<br \/>\npublic function border($width,$height,$color=&#8217;rgb(220,220,220)&#8217;){<br \/>\n$color=new ImagickPixel();<br \/>\n$color-&gt;setColor($color);<br \/>\n$this-&gt;image-&gt;borderImage($color,$width,$height);<br \/>\n}<br \/>\n\/\/\u53d6\u5f97\u56fe\u50cf\u5bbd\u5ea6<br \/>\npublic function get_width(){$size=$this-&gt;image-&gt;getImagePage();return $size[&#8216;width&#8217;];}<br \/>\n\/\/\u53d6\u5f97\u56fe\u50cf\u9ad8\u5ea6<br \/>\npublic function get_height(){$size=$this-&gt;image-&gt;getImagePage();return $size[&#8216;height&#8217;];}<br \/>\n\/\/ \u8bbe\u7f6e\u56fe\u50cf\u7c7b\u578b<br \/>\npublic function set_type($type=&#8217;png&#8217;){$this-&gt;type=$type;$this-&gt;image-&gt;setImageFormat($type);}<br \/>\n\/\/ \u53d6\u5f97\u56fe\u50cf\u7c7b\u578b<br \/>\npublic function get_type(){return $this-&gt;type;}<br \/>\npublic function blur($radius,$sigma){$this-&gt;image-&gt;blurImage($radius,$sigma);} \/\/ \u6a21\u7cca<br \/>\npublic function gaussian_blur($radius,$sigma){$this-&gt;image-&gt;gaussianBlurImage($radius,$sigma);} \/\/ \u9ad8\u65af\u6a21\u7cca<br \/>\npublic function motion_blur($radius,$sigma,$angle){$this-&gt;image-&gt;motionBlurImage($radius,$sigma,$angle);} \/\/ \u8fd0\u52a8\u6a21\u7cca<br \/>\npublic function radial_blur($radius){$this-&gt;image-&gt;radialBlurImage($radius);} \/\/ \u5f84\u5411\u6a21\u7cca<br \/>\npublic function add_noise($type=null){$this-&gt;image-&gt;addNoiseImage($type==null?imagick::NOISE_IMPULSE:$type);} \/\/ \u6dfb\u52a0\u566a\u70b9<br \/>\npublic function level($black_point,$gamma,$white_point){$this-&gt;image-&gt;levelImage($black_point,$gamma,$white_point);} \/\/ \u8c03\u6574\u8272\u9636<br \/>\npublic function modulate($brightness,$saturation,$hue){$this-&gt;image-&gt;modulateImage($brightness,$saturation,$hue);} \/\/ \u8c03\u6574\u4eae\u5ea6,\u9971\u548c\u5ea6,\u8272\u8c03<br \/>\npublic function charcoal($radius,$sigma){$this-&gt;image-&gt;charcoalImage($radius,$sigma);} \/\/ \u7d20\u63cf\u6548\u679c<br \/>\npublic function oil_paint($radius){$this-&gt;image-&gt;oilPaintImage($radius);} \/\/ \u6cb9\u753b\u6548\u679c<br \/>\npublic function flop(){$this-&gt;image-&gt;flopImage();} \/\/ \u6c34\u5e73\u7ffb\u8f6c<br \/>\npublic function flip(){$this-&gt;image-&gt;flipImage();} \/\/ \u5782\u76f4\u7ffb\u8f6c<br \/>\n}<\/p>\n<p>\u72b6\u51b5\u4e8c\u7684\u89e3\u51b3\u529e\u6cd5\u5982\u4e0b:<\/p>\n<p>\u9996\u5148\u7528\/usr\/local\/imagemagick\/bin\/convert -version\u6307\u4ee4\u67e5\u770b\u4e00\u4e0b\u8f93\u51fa\u5185\u5bb9\u662f\u5426\u5df2\u7ecf\u5f00\u555f\u4e86\u591a\u7ebf\u7a0b,Features:\u7684\u503c\u4e3a\u7a7a\u8bf4\u660e\u662f\u5355\u7ebf\u7a0b,\u5982\u679cFeatures:\u7684\u503c\u662fopenMP\u8bf4\u660e\u662f\u591a\u7ebf\u7a0b.imagick\u7684\u591a\u7ebf\u7a0b\u6a21\u5f0f\u6709\u4e00\u4e2abug,\u4ed6\u4f1a\u5bfc\u81f4\u591a\u6838\u5fc3\u7684cpu\u4f7f\u7528\u7387\u77ac\u95f4\u98c6\u5347\u5230100\u6240\u4ee5\u4e00\u5b9a\u8981\u4f7f\u7528\u5b83\u7684\u5355\u7ebf\u7a0b\u6a21\u5f0f\u624d\u884c.<\/p>\n<p>Version: ImageMagick 6.7.1-2 2014-05-29 Q16 http:\/\/www.imagemagick.org<br \/>\nCopyright: Copyright (C) 1999-2011 ImageMagick Studio LLC<br \/>\nFeatures:<\/p>\n<p>\u4e0a\u8fb9\u662f\u6211\u914d\u7f6e\u6b63\u786e\u65f6\u663e\u793a\u7684\u7ed3\u679c,\u5982\u679c\u6ca1\u6709\u914d\u7f6e\u6b63\u786e\u4f1a\u663e\u793a\u4e0b\u8fb9\u7684\u7ed3\u679c<\/p>\n<p>Version: ImageMagick 6.7.1-2 2014-05-29 Q16 http:\/\/www.imagemagick.org<br \/>\nCopyright: Copyright (C) 1999-2011 ImageMagick Studio LLC<br \/>\nFeatures: openMP<\/p>\n<p>\u7b2c\u4e00\u79cd\u7ed3\u679c\u662f\u5355\u7ebf\u7a0b\u6a21\u5f0f,\u7b2c\u4e8c\u79cd\u7ed3\u679c\u662f\u591a\u7ebf\u7a0b\u6a21\u5f0f,\u56e0\u4e3aimagick\u7684\u591a\u7ebf\u7a0b\u6a21\u5f0f\u6709bug,\u6240\u4ee5\u5982\u679c\u60a8\u521a\u5f00\u59cb\u662f\u7528\u591a\u7ebf\u7a0b\u6a21\u5f0f\u5b89\u88c5\u7684imagick\u90a3\u5c31\u5fc5\u987b\u8981yum remove imagemagick\u5c06\u5176\u5378\u8f7d\u6389\u91cd\u65b0\u5b89\u88c5\u624d\u884c.<\/p>\n<p>\u7ecf\u8fc7\u91cd\u5199class,\u91cd\u88c5imagick\u4e4b\u540e\u4e00\u5207\u6b63\u5e38,\u800c\u4e14\u5904\u7406\u56fe\u50cf\u7684\u6548\u80fd\u6bd4\u4e4b\u4ee5\u524d\u6709\u4e86\u5927\u5e45\u63d0\u5347<\/p>\n","protected":false},"excerpt":{"rendered":"<p>imagick\u662f\u4e00\u4e2a\u53ef\u4ee5\u4f9bPHP\u8c03\u7528ImageMagick\u529f\u80fd\u7684PHP\u6269\u5c55\u3002\u4f7f\u7528\u8fd9\u4e2a\u6269\u5c55\u53ef\u4ee5\u4f7fPHP\u5177\u5907\u548cIm [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-411","post","type-post","status-publish","format-standard","hentry","category-php"],"_links":{"self":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/411","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=411"}],"version-history":[{"count":1,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/411\/revisions"}],"predecessor-version":[{"id":412,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=\/wp\/v2\/posts\/411\/revisions\/412"}],"wp:attachment":[{"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=411"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=411"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.siediyer.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=411"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}