I am trying to recompile ImageMagick to enable webp support for PHP.
The issue appears to be that when compiling Imagick using ./configure --with-webp=yes
it cannot find a libwebp library with a higher version than 0.4.1
. Amazon Linux 2’s repos only go up to version 0.3.1
. This means compiling libwebp from source, which works but Imagick does not seem to recognize it.
So my question is, how do I ensure ImageMagick can find and use the libwebp library?
Steps
To compile from the source I have done the following:
cd /var
sudo wget https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.1.0.tar.gz
sudo tar xvzf libwebp-1.1.0.tar.gz
cd libwebp-1.1.0
sudo ./configure
sudo make && sudo make install
/sbin/ldconfig -p | grep webp
shows the following output which shows libwebp library exists in the /usr/local/lib
dir as expected and registered in the ld config.
libwebpdemux.so.2 (libc6,x86-64) => /usr/local/lib/libwebpdemux.so.2
libwebpdemux.so (libc6,x86-64) => /usr/local/lib/libwebpdemux.so
libwebp.so.7 (libc6,x86-64) => /usr/local/lib/libwebp.so.7
libwebp.so (libc6,x86-64) => /usr/local/lib/libwebp.so
I then try to compile Imagick from source by doing the following:
cd /var
sudo wget https://imagemagick.org/download/ImageMagick.tar.gz
sudo tar xvzf ImageMagick.tar.gz
cd ImageMagick-7.1.0-7
sudo ./configure --with-webp=yes
sudo make && sudo make install
sudo ldconfig /usr/local/lib
However, when running ./configure --with-webp=yes
, I get the following output
...
-------------------------------------------------------------
checking for libwebp >= 0.4.1... no
checking for libwebpmux >= 0.5.0 libwebpdemux >= 0.5.0... no
checking if WMF package is complete... no
-------------------------------------------------------------
...
configure:
==============================================================================
ImageMagick 7.1.0-7 is configured as follows. Please verify that this
configuration matches your expectations.
Host system type: x86_64-pc-linux-gnu
Build system type: x86_64-pc-linux-gnu
Option Value
------------------------------------------------------------------------------
Shared libraries --enable-shared=yes yes
Static libraries --enable-static=yes yes
Build utilities --with-utilities=yes yes
Module support --with-modules=no no
GNU ld --with-gnu-ld=yes yes
Quantum depth --with-quantum-depth=16 16
High Dynamic Range Imagery
--enable-hdri=yes yes
Install documentation: yes
Memory allocation library:
JEMalloc --with-jemalloc=no no
TCMalloc --with-tcmalloc=no no
UMem --with-umem=no no
Delegate library configuration:
BZLIB --with-bzlib=yes no
Autotrace --with-autotrace=no no
DJVU --with-djvu=yes no
DPS --with-dps=yes no
FFTW --with-fftw=no no
FLIF --with-flif=yes no
FlashPIX --with-fpx=yes no
FontConfig --with-fontconfig=yes no
FreeType --with-freetype=yes no
Ghostscript lib --with-gslib=no no
Graphviz --with-gvc=yes no
HEIC --with-heic=yes no
JBIG --with-jbig=yes no
JPEG v1 --with-jpeg=yes yes
JPEG XL --with-jxl=no no
LCMS --with-lcms=yes no
LQR --with-lqr=yes no
LTDL --with-ltdl=no no
LZMA --with-lzma=yes no
Magick++ --with-magick-plus-plus=yes no (failed tests)
OpenEXR --with-openexr=yes no
OpenJP2 --with-openjp2=yes no
PANGO --with-pango=yes no
PERL --with-perl=no no
PNG --with-png=yes yes
RAQM --with-raqm=yes no
RAW --with-raw=yes no
RSVG --with-rsvg=no no
TIFF --with-tiff=yes yes
WEBP --with-webp=yes no
WMF --with-wmf=no no
X11 --with-x= no
XML --with-xml=yes no
ZIP --with-zip=yes no
ZLIB --with-zlib=yes yes
ZSTD --with-zstd=yes no
Delegate program configuration:
GhostPCL None pcl6 (unknown)
GhostXPS None gxps (unknown)
Ghostscript None gs (9.25)
Font configuration:
Apple fonts --with-apple-font-dir=default
Dejavu fonts --with-dejavu-font-dir=default none
Ghostscript fonts --with-gs-font-dir=default /share/ghostscript/fonts/
URW-base35 fonts --with-urw-base35-font-dir=default none
Windows fonts --with-windows-font-dir=default none
X11 configuration:
X_CFLAGS =
X_PRE_LIBS =
X_LIBS =
X_EXTRA_LIBS =
Options used to compile and link:
PREFIX = /usr/local
EXEC-PREFIX = /usr/local
VERSION = 7.1.0-7
CC = gcc
CFLAGS = -I/usr/include/libpng15 -fopenmp -Wall -g -O2 -mtune=haswell -fexceptions -pthread -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16
CPPFLAGS = -DMAGICKCORE_HDRI_ENABLE=1 -DMAGICKCORE_QUANTUM_DEPTH=16
PCFLAGS =
DEFS = -DHAVE_CONFIG_H
LDFLAGS =
LIBS = -ltiff -ljpeg -lpng15 -lz -lm -lpthread
CXX = g++
CXXFLAGS = -pthread
FEATURES = DPC HDRI Cipher OpenMP
DELEGATES = jng jpeg png ps tiff zlib
==============================================================================
Related posts:
https://github.com/rosell-dk/webp-convert/wiki/Installing-Imagick-extension-with-WebP-support
https://legacy.imagemagick.org/discourse-server/viewtopic.php?t=35892
Add WebP to ImageMagick supported formats for PHP 7.3 on a WHM dedicated server
https://library.roguewave.com/display/SUPPORT/How+to+compile+Imagick+PHP+extension+with+WebP+support
3
Answers
For the libraries to be found, you’ve got to make sure pkgconfig sees the .pc files
/usr/lib/pkgconfig
Add
export PKG_CONFIG_PATH=/usr/lib/pkgconfig:$PKG_CONFIG_PATH
to your.bash_profile
, source it and check usingpkg-config --list-all | grep webp
.If the libraries are found, try
./configure --with-webp=yes
again.I recently had a similar issue when trying to configure ImageMagick-7.1.0 on Amazon Linux 2022.
When I ran
pkg-config --list-all | grep webp
per @Juukie14’s suggestion, I received:For whatever reason, pkg-config installed from the AL2022 package repository is looking for
arch64-redhat-linux-gnu-pkg-config
when it should be/usr/bin/aarch64-amazon-linux-gnu-pkg-config
.As a workaround, I created a symlink:
After this, I ran
./configure --with-webp=yes
and it worked.I fixed the problem by adding
/usr/local/lib/pkgconfig
to the PKG_CONFIG_PATH like thatThen configuring and installing ImageMagick completed successfully with webp support.