安装ImageMagick7.1库以及php的Imagick扩展
阅读原文时间:2022年06月24日阅读:2

由于ImageMagick7以下不支持heic等图片格式,所以重新安装了ImageMagick7.1版本支持heic格式,并写此文章记录一下。

如果安装过程中遇到一些未知的错误,https://imagemagick.org/script/download.php 可以去官网看文档解决,或者评论一起解决。

在Linux(centos7)上安装ImageMagick7.1库以及php的Imagick扩展

安装之前需要配置一下pkg-config,以便 ImageMagick 可以在您的系统上找到某些可选的委托库

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/lib64/pkgconfig:/usr/local/lib/pkgconfig

export PKG_CONFIG_PATH

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/lib64:/usr/local/lib:/usr/local/lib64

export LD_LIBRARY_PATH

安装依赖库(这里我只安装heic(heif) 的依赖,其他格式类似一样安装)

安装x265(libheif依赖)

wget https://www.nasm.us/pub/nasm/releasebuilds/2.13.03/nasm-2.13.03.tar.gz

tar -zxvf nasm-2.13.03.tar.gz

cd nasm-2.13.03

./autogen.sh && ./configure && make && make install

安装libheif依赖

wget https://github.com/strukturag/libheif/releases/download/v1.12.0/libheif-1.12.0.tar.gz

tar -zxvf libheif-1.12.0.tar.gz

cd libheif-1.12.0

./autogen.sh && ./configure && make && make install

最后安装ImageMagick

wget https://imagemagick.org/archive/ImageMagick-7.1.0-39.tar.gz

tar -zxvf ImageMagick-7.1.0-39.tar.gz

cd ImageMagick-7.1.0-39

./configure && make && make install

设置环境变量

echo "export PATH=$PATH:/usr/local/ImageMagick/bin" >> /etc/profile

//如果需要移除旧版本

yum remove ImageMagick -y

//加载环境变量

source /etc/profile

//验证版本安装是否成功

convert -version

//查看支持格式列表

convert -list format

在编译的过程中如果出现报错

error: 'libraw_output_params_t' has no member named 'no_interpolation'

则需要升级一下你的 libraw 版本

//先卸载当前libraw

yum remove libraw

//安装更高版本的libraw

(rpm安装命令)

rpm -ivh https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/LibRaw-0.19.4-1.el7.x86_64.rpm

(yum安装命令)

yum localinstall -y https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/Packages/LibRaw-0.19.4-1.el7.x86_64.rpm

安装完重新编辑即可

//下载、解压、安装imagick-3.4.4

wget https://pecl.php.net/get/imagick-3.4.4.tgz

tar -zxvf imagick-3.4.4.tgz

cd imagick-3.4.4.tgz/

/usr/local/php/bin/phpize

//ImageMagick 6.8以上版本目录为/usr/local/include/ImageMagick-X,在configure之前先做下软连接

ln -s /usr/local/imagemagick/include/ImageMagick-7 /usr/local/imagemagick/include/ImageMagick

./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick

make && make install

最后在php.ini中加入imagick.so扩展即可

extensions=imagick.so

通过升级ImageMagick7支持heic格式处理,由于我们服务器是aws的,在安装的过程中可谓一波三折。不过好在最终也是成功安装完成。希望记录下来过程,给有需要的朋友们一点帮助。

博客地址:https://www.goldenleek.top

欢迎骚扰~

手机扫一扫

移动阅读更方便

阿里云服务器
腾讯云服务器
七牛云服务器

你可能感兴趣的文章