介绍
下载安装
imagick地址:http://pecl.php.net/package/imagick
imagick下载备用地址:http://download.csdn.net/detail/webben/9787243
PHP Version 5.6.3
imagick 3.3.0
下载:
#安装ImageMagick-devel
yum install ImageMagick-devel
cd /usr/local/src/
#下载
wget http://pecl.php.net/get/imagick-3.3.0.tgz
#解压
tar -zxvf imagick-3.3.0.tgz
#安装PHP imsgick扩展
cd imagick-3.3.0
#phpize
/usr/local/php/bin/phpize
#配置
./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/src/imagick-3.3.0
#安装
make && make install
#出现以下代表安装php扩展成功
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
Installing header files: /usr/local/php/include/php/
#配置php.ini
vim /usr/local/php/etc/php.ini
#增加
extension=imagick.so
#重启web服务或者php-fpm
service php-fpm restart
#测试
php -r 'phpinfo();' | grep imagick
imagick
imagick module => enabled
imagick module version => 3.3.0
测试
PHP给图片添加水印,水平铺满。
$image = new imagick('logo.jpg');
$im = new imagick();
$im->newimage( 140, 80, new imagickpixel( "none" ) );
$draw = new imagickdraw();
$draw->setfillcolor(new imagickpixel( "grey" ));
$draw->setgravity(imagick::GRAVITY_NORTHWEST);
$draw->annotation(10,10 ,'copyright');
$draw->setgravity(imagick::GRAVITY_SOUTHEAST);
$draw->annotation(5,15 ,'copyright');
$im->drawimage( $draw);
$image = $image->textureimage($im);
$image->compositeimage($image,imagick::COMPOSITE_COPY,0,0);
header( "content-type: image/{$image->getimageformat()}" );
$image->writeimage('wmark_text_tiled.jpg');
$image->clear();
$image->destroy();