参考:
《 linux环境下安装php_imagick扩展,linux php ImageMagick缺少jpg,png,tiff格式 》
《 imagick扩展不支持jpg 》
1. docker镜像编译
直接下载使用:docker pull cffycls/phpswoole:imagick-dev
,跳过下文。
或重新手动编译imagick依赖
# PHPIZE_DEPS 参考于: https://github.com/hyperf/hyperf-docker/blob/master/8.1/alpine/swoole/Dockerfile
ENV PHPIZE_DEPS="autoconf dpkg-dev dpkg file g++ gcc libc-dev make php8-dev php8-pear pkgconf re2c pcre-dev pcre2-dev zlib-dev libtool automake"
ENV IMAGICK_DEPS="libgomp libzip zstd-libs imagemagick-dev"
COPY ./ /tmp/
RUN set -ex \
&& pecl update-channels \
&& apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
\
&& apk add $IMAGICK_DEPS \
# 最新版支持列表 https://download.imagemagick.org/ImageMagick/download/delegates/
# 20220517.安装 jpeg
# && wget http://www.ijg.org/files/jpegsrc.v9b.tar.gz \
&& cd /tmp/ && tar -zxf jpegsrc.v9b.tar.gz && cd jpeg-9b/ \
&& ./configure --prefix=/usr/local/jpeg/ \
&& make -j4 && make install -j4 \
&& ls -l /usr/local/jpeg \
# && wget https://download.imagemagick.org/ImageMagick/download/delegates/libpng-1.6.31.tar.gz \
&& cd /tmp/ && tar -zxf libpng-1.6.31.tar.gz && cd libpng-1.6.31/ \
&& ./configure --prefix=/usr/local/png/ \
&& make -j4 && make install -j4 \
&& ls -l /usr/local/png \
\
# && wget https://download.imagemagick.org/ImageMagick/download/delegates/freetype-2.8.1.tar.gz \
&& cd /tmp/ && tar -zxf freetype-2.8.1.tar.gz && cd freetype-2.8.1/ \
&& ./configure --prefix=/usr/local/freetype/ \
&& make -j4 && make install -j4 \
&& ls -l /usr/local/freetype \
\
# && wget https://download.imagemagick.org/ImageMagick/download/delegates/tiff-4.0.8.tar.gz \
&& cd /tmp/ && tar -zxf tiff-4.0.8.tar.gz && cd tiff-4.0.8/ \
&& ./configure --prefix=/usr/local/tiff/ \
&& make -j4 && make install -j4 \
&& ls -l /usr/local/tiff \
\
\
# 安装 ImageMagick
# && wget http://www.imagemagick.org/download/ImageMagick.tar.gz \
&& cd /tmp/ && tar -zxf ImageMagick.tar.gz && cd ImageMagick-7.1.0-34/ \
&& ./configure --prefix=/usr/local/imagemagick \
CPPFLAGS="-I/usr/local/jpeg -I/usr/local/jpeg/include -I/usr/local/png -I/usr/local/png/include -I/usr/local/freetype -I/usr/local/freetype/include -I/usr/local/tiff -I/usr/local/tiff/include" \
LDFLAGS="-L/usr/local/lib -L/usr/local/jpeg/lib -L/usr/local/png/lib -L/usr/local/freetype/lib -L/usr/local/tiff/lib" \
&& make -j4 && make install -j4 \
&& ls -l /usr/local/imagemagick \
\
\
# 安装 ImageMagick
# git ssl问题无法下载,在浏览器下载复制
&& cd /tmp/imagick-master/ \
&& phpize \
&& ./configure --with-php-config=/usr/local/bin/php-config --with-imagick=/usr/local/imagemagick \
&& make -j4 && make install -j4 \
\
&& /usr/local/imagemagick/bin/convert --version \
&& docker-php-ext-enable imagick \
# ---------- clear works ----------
&& apk del .build-deps \
&& rm -rf /var/cache/apk/* /tmp/*
2. 环境构建问题的处理
a. 编译后与调试期间不一致问题解决
在 安装 ImageMagick
前增加环境变量设置
\
# ***** 配置环境库变量 *****
# && echo -e "LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:/usr/local/lib:/usr/local/jpeg/lib:/usr/local/png/lib:/usr/local/freetype/lib:/usr/local/tiff/lib \n export LD_LIBRARY_PATH" >> /etc/profile \
&& echo -e "/usr/local/jpeg/lib \n/usr/local/png/lib \n/usr/local/freetype/lib \n/usr/local/tiff/lib \n/usr/local/imagemagick/lib \n/usr/local/lib" > /etc/ld.so.conf \
\
# 安装 ImageMagick
后面逐渐使用 --prefix=/usr/
的系统默认路径,把库文件直接放到系统默认目录中,取消了这个设置。
b. 编译结果:
Delegates (built-in):
bzlib cairo fontconfig freetype gslib heic jng jpeg lcms ltdl lzma png ps rsvg tiff webp x xml zlib
#/ /usr/local/imagemagick/bin/convert --version
Version: ImageMagick 7.0.11-14 Q16 x86_64 2021-05-31 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules
Delegates (built-in): bzlib cairo fontconfig freetype gslib heic jng jpeg lcms ltdl lzma png ps rsvg tiff webp x xml zlib
c. 运行出现新问题
Imagick was compiled against ImageMagick version 1808 but version 1803 is loaded. Imagick will run but may behave surprisingly in Unknown on line 0
这个说明是php-imagick自身api扩展版本低了,查看扩展页面
http://pecl.php.net/package/imagick ==> https://phpimagick.com/
所示扩展的最高支持版本信息:
versionString = ImageMagick 7.1.0-17 Q16-HDRI x86_64 2021-11-21 https://imagemagick.org
考虑到git上查找历史版本并重新编译:
https://github.com/ImageMagick/ImageMagick/releases
能用的版本是 7.1.0-15[21 Nov 2021] 不早于 7.1.0-17[2021-11-21] ,所以使用下载这个7.1.0-15重新构建编译。
d. 最终编译结果
Delegates (built-in):
freetype jng jpeg png tiff zlib
#/ /usr/local/imagemagick/bin/convert --version
Version: ImageMagick 7.1.0-15 Q16-HDRI x86_64 2021-11-14 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(4.5)
Delegates (built-in): freetype jng jpeg png tiff zlib
Compiler: gcc (10.2)
# php --ri imagick
imagick
imagick module => enabled
imagick module version => @PACKAGE_VERSION@
imagick classes => Imagick, ImagickDraw, ImagickPixel, ImagickPixelIterator, ImagickKernel
Imagick compiled with ImageMagick version => ImageMagick 7.1.0-15 Q16-HDRI x86_64 2021-11-14 https://imagemagick.org
Imagick using ImageMagick library version => ImageMagick 7.1.0-15 Q16-HDRI x86_64 2021-11-14 https://imagemagick.org
ImageMagick copyright => (C) 1999-2021 ImageMagick Studio LLC
ImageMagick release date => 2021-11-14
ImageMagick number of supported formats: => 246
ImageMagick supported formats => 3FR, 3G2, 3GP, A, AAI, AI, APNG, ART, ARW, ASHLAR, AVI, AVS, B, BGR, BGRA, BGRO, BMP, BMP2, BMP3, BRF, C, CAL, CALS, CANVAS, CAPTION, CIN, CIP, CLIP, CMYK, CMYKA, CR2, CR3, CRW, CUBE, CUR, CUT, DATA, DCM, DCR, DCRAW, DCX, DDS, DFONT, DNG, DPX, DXT1, DXT5, EPDF, EPI, EPS, EPS2, EPS3, EPSF, EPSI, EPT, EPT2, EPT3, ERF, FARBFELD, FAX, FF, FILE, FITS, FL32, FLV, FRACTAL, FTP, FTS, G, G3, G4, GIF, GIF87, GRADIENT, GRAY, GRAYA, GROUP4, HALD, HDR, HISTOGRAM, HRZ, HTM, HTML, HTTP, HTTPS, ICB, ICO, ICON, IIQ, INFO, INLINE, IPL, ISOBRL, ISOBRL6, JNG, JNX, JPE, JPEG, JPG, JPS, JSON, K, K25, KDC, LABEL, M, M2V, M4V, MAC, MAP, MASK, MAT, MATTE, MEF, MIFF, MKV, MNG, MONO, MOV, MP4, MPC, MPEG, MPG, MRW, MSL, MSVG, MTV, MVG, NEF, NRW, NULL, O, ORA, ORF, OTB, OTF, PAL, PALM, PAM, PANGO, PATTERN, PBM, PCD, PCDS, PCL, PCT, PCX, PDB, PDF, PDFA, PEF, PES, PFA, PFB, PFM, PGM, PGX, PHM, PICON, PICT, PIX, PJPEG, PLASMA, PNG, PNG00, PNG24, PNG32, PNG48, PNG64, PNG8, PNM, POCKETMOD, PPM, PS, PS2, PS3, PSB, PSD, PTIF, PWP, R, RADIAL-GRADIENT, RAF, RAS, RAW, RGB, RGB565, RGBA, RGBO, RGF, RLA, RLE, RMF, RW2, SCR, SCREENSHOT, SCT, SFW, SGI, SHTML, SIX, SIXEL, SPARSE-COLOR, SR2, SRF, STEGANO, SUN, SVG, SVGZ, TEXT, TGA, THUMBNAIL, TIFF, TIFF64, TILE, TIM, TM2, TTC, TTF, TXT, UBRL, UBRL6, UIL, UYVY, VDA, VICAR, VID, VIFF, VIPS, VST, WBMP, WEBM, WMV, WPG, X3F, XBM, XC, XCF, XPM, XPS, XV, Y, YAML, 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.set_single_thread => 1 => 1
imagick.shutdown_sleep_count => 10 => 10
imagick.allow_zero_dimension_images => 0 => 0
3. 最终编译参数
RUN set -ex \
&& pecl update-channels \
&& apk add --no-cache --virtual .build-deps $PHPIZE_DEPS \
&& pecl install redis \
&& docker-php-ext-enable redis \
\
&& apk add $IMAGICK_DEPS \
# 下载页面:最新版支持列表 https://download.imagemagick.org/ImageMagick/download/delegates/
# 20220517.安装 jpeg
# && wget http://www.ijg.org/files/jpegsrc.v9b.tar.gz \
&& cd /tmp/ && tar -zxf jpegsrc.v9b.tar.gz && cd jpeg-9b/ \
&& ./configure --prefix=/usr/ \
&& make clean && make -j4 && make install -j4 \
\
# && wget https://download.imagemagick.org/ImageMagick/download/delegates/libpng-1.6.31.tar.gz \
&& cd /tmp/ && tar -zxf libpng-1.6.31.tar.gz && cd libpng-1.6.31/ \
&& ./configure --prefix=/usr/ \
&& make clean && make -j4 && make install -j4 \
\
# && wget https://download.imagemagick.org/ImageMagick/download/delegates/freetype-2.8.1.tar.gz \
&& cd /tmp/ && tar -zxf freetype-2.8.1.tar.gz && cd freetype-2.8.1/ \
&& ./configure --prefix=/usr/ \
&& make clean && make -j4 && make install -j4 \
\
# && wget https://download.imagemagick.org/ImageMagick/download/delegates/tiff-4.0.8.tar.gz \
&& cd /tmp/ && tar -zxf tiff-4.0.8.tar.gz && cd tiff-4.0.8/ \
&& ./configure --prefix=/usr/ \
&& make clean && make -j4 && make install -j4 \
\
\
# 安装 ImageMagick 下载页面 https://github.com/ImageMagick/ImageMagick/releases
&& cd /tmp/ && tar -zxf ImageMagick-7.1.0-15.tar.gz && cd ImageMagick-7.1.0-15/ \
&& ./configure --prefix=/usr/local/imagemagick \
&& make clean && make -j4 && make install -j4 \
&& /usr/local/imagemagick/bin/convert --version \
\
\
# 安装 ImageMagick
# git ssl问题无法下载,在浏览器下载复制 https://github.com/Imagick/imagick.git
&& cd /tmp/imagick-master/ \
&& phpize \
&& ./configure --with-php-config=/usr/local/bin/php-config --with-imagick=/usr/local/imagemagick \
&& make clean && make -j4 && make install -j4 \
\
&& docker-php-ext-enable imagick \
&& php --ri imagick \
# ---------- clear works ----------
&& apk del .build-deps \
&& rm -rf /var/cache/apk/* /tmp/*
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。