php8 Imagick庫缺失jpeg、png、tiff等格式的問題

滄浪水發表於2022-05-18

參考:

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. 編譯後與除錯期間不一致問題解決

安裝 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

3. 最終編譯結果:

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

相關文章