centos7环境下安装php7.2.24的imagick和rdkafka扩展
centos7环境下安装php7.2.24的imagick扩展
测试环境是ok的,为了保持一致性版本和测试环境一致
获取版本信息
# php --ri imagick imagick imagick module => enabled imagick module version => 3.4.4 imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel Imagick compiled with ImageMagick version => ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org Imagick using ImageMagick library version => ImageMagick 6.9.10-23 Q16 x86_64 20190101 https://imagemagick.org ImageMagick copyright => © 1999-2019 ImageMagick Studio LLC ImageMagick release date => 20190101 ImageMagick number of supported formats: => 242 ImageMagick supported formats => 3FR, 3G2, 3GP, AAI, AI, ART, ARW, AVI, AVS, BGR, BGRA, BGRO, BIE, BMP, BMP2, BMP3, BRF, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CRW, CUR, CUT, DATA, DCM, DCR, DCX, DDS, DFONT, DJVU, DNG, DOT, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, EXR, FAX, FILE, FITS, FRACTAL, FTP, FTS, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, GV, H, HALD, HDR, HEIC, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, J2C, J2K, JBG, JBIG, JNG, JNX, JP2, JPC, JPE, JPEG, JPG, JPM, JPS, JPT, JSON, K25, KDC, LABEL, M2V, M4V, MAC, MAGICK, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, PPM, PREVIEW, PS, PS2, PS3, PSB, PSD, PTIF, PWP, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WEBP, WMF, WMV, WMZ, WPG, X, X3F, XBM, XC, XCF, XPM, XPS, XV, XWD, YCbCr, YCbCrA, YUV Directive => Local Value => Master Value imagick.locale_fix => 0 => 0 imagick.skip_version_check => 0 => 0 imagick.progress_monitor => 0 => 0
可以看到版本信息:
imagick module version => 3.4.4
ImageMagick 6.9.10-23
# 安装依赖
yum install ImageMagick-devel -y
1.安装依赖ImageMagick
下载地址:http://www.imagemagick.org/download/releases/
cd /usr/local/src
wget http://www.imagemagick.org/download/releases/ImageMagick-6.9.10-33.tar.xz
tar xf ImageMagick-6.9.10-33.tar.xz
cd ImageMagick-6.9.10-33
./configure --prefix=/usr/local/imagemagick
make && make install
2.安装imagick
在这里查到下载页面
https://pecl.php.net/packages.php
下载页面:https://github.com/Imagick/imagick/releases
cd /usr/local/src
wget http://pecl.php.net/get/imagick-3.4.4.tgz
tar xf imagick-3.4.4.tgz
cd imagick-3.4.4
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick/
make && make install
# 图片转换的脚本 将当前的 Plant_004.svg 文件转成 output.png
<?php /** * Created by graph-design-api. * AUTHOR: * Date: 2020/10/29 15:13 */ try { $im = new \Imagick(); $svg = file_get_contents("./Plant_004.svg"); $p = '/^(.*)width=([\'\"])([\d\.]+)(\w+)([\'\"])(.*)height=([\'\"])([\d\.]+)(\w+)([\'\"])(.*)$/'; if (preg_match($p, $svg)) { $svg = preg_replace($p, "$1width=$2$3$5$6height=$7$8$10$11", $svg); } $im->readImageBlob($svg); $im->setImageFormat("png24"); $srcImage = $im->getImageGeometry(); $im->resizeImage(100, 100, \Imagick::FILTER_LANCZOS, 1, TRUE); $im->writeImage('output.png'); $im->clear(); $im->destroy(); } catch (\Exception $e) { die($e->getMessage()); }
# 图片转换报错:
# php imagick.php
unable to load module `/usr/lib64/ImageMagick-6.9.10/modules-Q16/coders/svg.la': file not found @ error/module.c/OpenModule/1316
安装依赖
cd /usr/local/src
wget https://sourceforge.net/projects/re2c/files/0.16/re2c-0.16.tar.gz
tar zxf re2c-0.16.tar.gz
cd re2c-0.16
./configure
make && make install
cd /usr/local/src
wget https://github.com/edenhill/librdkafka/archive/v1.5.0.tar.gz
tar xf v1.5.0.tar.gz
cd librdkafka-1.5.0
cd librdkafka
./configure
make && make install
ln -s /usr/local/lib/librdkafka.so.1 /usr/lib/
cd /usr/local/src
wget https://github.com/arnaud-lb/php-rdkafka/archive/4.0.3.tar.gz
tar xf 4.0.3.tar.gz
cd php-rdkafka-4.0.3
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
# 添加rdkafka 模块
vim /usr/local/php/lib/php.ini
extension=rdkafka.so
php -m|grep kaf
rdkafka