PHP imagick安裝與配置
阿新 • • 發佈:2018-12-23
介紹
下載安裝
下載:
#安裝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();