最近项目中需要用到图片的一些特殊处理——比如:根据用户请求生成任意尺寸的图像。经过一些资料的查找,最终选用了php_imagick。利用 ImageMagick,你可以根据web应用程序的需要动态生成图片, 还可以对一个(或一组)图片进行改变大小、旋转、锐化、减色或增加特效等操作,并将操作的结果以相同格式或其它格式保存。本节我们就来介绍一下如何在 windows下安装php_imagick拓展。
1. 下载 Download ImageMagick
#下载页面:
http://www.imagemagick.org/script/binary-releases.php#windows
(这里比较难下载到老的版本,如果需要老的版本,可以在csdn下载,或者在我博客留言,我可以提供)
#直接下载:
http://www.imagemagick.org/download/binaries/ImageMagick-6.6.3-0-Q16-windows-dll.exe
(此路径已经不可用,可以从csdn下载,或者在我博客留言,我可以提供)
 
注意:如果php是5.2.x版本的,需要匹配到imageMagick 6.8.9版本,可以在csdn上进行下载。
2. 安装 Install ImageMagick
安装路径随意,我的安装是:
D:\WampServer\bin\ImageMagick-6.6.3-Q16
3. 测试 Testing the Installation
如果不加入环境变量的话,可以先下面方式测试:
Open the command prompt (Run->”CMD”->ENTER) and type in convert and press enter. You should see the help parameters of convert
| 1 | cd D:\WampServer\bin\ImageMagick-6.6.3-Q16 # 回车 | 
 
| 2 | D:\WampServer\bin\ImageMagick-6.6.3-Q16>convert | 
 
| 3 | Version: ImageMagick 6.6.3-0 2010-07-01 Q16 http://www.imagemagick.org | 
 
| 4 | Copyright: Copyright (C) 1999-2010 ImageMagick Studio LLC | 
 
| 7 | Usage: Magick [options ...] file [ [options ...] file ...] [options ...] file | 
 
| 10 | -adjoin join images into a single multi-image file | 
 
| 11 | -affine matrix affine transform matrix | 
 
| 12 | -alpha option activate, deactivate, reset, or set the alpha channel | 
 
| 13 | -antialias remove pixel-aliasing | 
 
| 14 | -authenticate password | 
 
| 15 | decipher image with this password | 
 
| 16 | -attenuate value lessen (or intensify) when adding noise to an image | 
 
| 17 | -background color background color | 
 
| 18 | -bias value add bias when convolving an image | 
 
| 19 | -black-point-compensation | 
 
| 20 | use black point compensation | 
 
| 21 | -blue-primary point chromaticity blue primary point | 
 
| 22 | -bordercolor color border color | 
 
| 23 | -caption string assign a caption to an image
 | 
 
 
 
24.......
加入环境变量,方便以后使用(我的是WIndows7 系统):
我的电脑-》右键属性-》高级系统设置-》高级-》环境变量-》系统变量-》
-》找到Path, 点击编辑加入:
D:\WampServer\bin\ImageMagick-6.6.3-Q16;
加入完成之后,可以直接在命令行(CMD)使用convert了。
4. 下载DLL Downloading the php_Imagick.dll
Again the version problem, well if you are using PHP 5.2.x this is where you will get your dll.
我使用的是 (php5.2.9-2):php_imagick_dyn-Q16.dll
dyn = dynamic, st = static, q16 = 16 bit, q8= 8 bit. This should match your downloaded version of course. If you downloaded q16 dynamic library, your file will be php_imagick_dyn-Q16.dll
If you are using PHP 5.3.x, this is your location to download.
5. 编辑 PHP.ini
下载的php_imagick_dyn-Q16.dll需要改名为php_imagick.dll 然后保存到
D:\WampServer\bin\php\php5.2.9-2\ext\
然后编辑 PHP.ini
找到dll这里,加入下面的最后一行:
| 1 | ;extension=php_sybase_ct.dll | 
 
| 2 | ;extension=php_tidy.dll | 
 
| 3 | ;extension=php_xmlrpc.dll | 
 
| 6 | extension=php_imagick.dll | 
 
 
 
6. 重启Wamp
7. 通过查看phpinfo();
如果有imagick项应该成功了
8. 小测试
| 1 | $im= newimagick( 'a.jpg'); | 
 
| 3 | $im->thumbnailImage( 200, 0); | 
 
| 5 | $im->writeImage( 'a_thumbnail.jpg'); | 
 
 
 
好了,完成了。