Add WebP to ImageMagick supported formats for PHP 7.3 on a WHM dedicated server
Asked Answered
S

4

5

I am trying to add WebP to ImageMagick supported formats for PHP 7.3 on a WHM dedicated server. Whenever I was adding this question I saw other posts related to this problem but they don't have a solution as I tried everybody's recommendations from those answers.

Here is what the deal is. I want to be able to serve images in WebP format on all our websites hosted on our server. So I installed some plugins to do that but they are trowing this warning which is saying that WebP is a missing ImageMagick format. Well, whenever I am checking PHPINFO under ImageMagick supported formats WebP is really missing.

enter image description here

I am also getting this Notification from that plugin: EWWW Image Optimizer requires exec() to perform local compression. Your system administrator has disabled the exec() function, ask them to enable it.

So I went under the main PHP INI file and under disable_functions = I we don't have any function assigned.

So first I tried to install just libwebp library like this:

$ wget -c https://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-0.6.1-linux-x86-32.tar.gz
$ tar -xvf libwebp-0.6.1-linux-x86-32.tar.gz 
$ cd libwebp-0.6.1-linux-x86-32/
$ cd bin/
$ ls

After ls command I get this:

enter image description here

Ok, it is on the server, it is installed but it doesn't show up under ImageMagick supported formats so I tried to Install ImageMagick again from Unix Source.

After download I did tar xvzf ImageMagick.tar.gz

Next configure and compile ImageMagick.

$ cd ImageMagick-7.0.8
$ ./configure
$ make

Install

sudo make install

Configured the dynamic linker run-time bindings:

sudo ldconfig /usr/local/lib

And then I wanted to run the ImageMagick validation suite:

make check

All this worked without any complaint or errors but whenever I check PHPINFO it still doesn't show any changes. What am I doing wrong here? How can I configure the PHP or what am I missing?

Thank you!

Seibel answered 26/7, 2019 at 15:36 Comment(1)
Install libwebp where ImageMagick is located or where it can find it. Install ImageMagick. Check if installed via convert -version. webp should show in the list of delegates. If not, then be sure when you installed webp that it did not have any error or need other dependencies installed first.Viewable
P
7

Before going further, remove all webp previous installation.

To install Imagick with webp support you should:

Install wepb from source:

  1. wget http://storage.googleapis.com/downloads.webmproject.org/releases/webp/libwebp-1.1.0.tar.gz
  2. tar xvzf libwebp-1.1.0.tar.gz
  3. cd libwebp-1.1.0
  4. ./configure
  5. make && sudo make install

Install Imagick from source with webp support:

  1. wget https://imagemagick.org/download/ImageMagick.tar.gz
  2. ./configure --with-webp=yes
  3. sudo make && sudo make install

Install Imagick using PECL:

  1. sudo pecl install imagick
  2. sudo echo "extension=gmagick.so" > sudo /etc/php/7.3/apache2/conf.d/20-imagick.ini
  3. Restart apache sudo apache2ctl restart

To check if it works from the CLI:

php -r "print_r(Imagick::queryFormats());"

And you should see "WEBP" in the list.

Potence answered 24/4, 2020 at 5:13 Comment(0)
N
2

This problem stems from the fact that the CentOS provided package for ImageMagick is not compiled with support for WebP.

There are three workarounds/solutions to this problem:

  1. If you are using ALT-PHP (CloudLinux provided PHP) with cPanel, it comes with its own version of ImageMagick that was compiled with webp support. Of course, use of ALT-PHP requires the extra cost of a CloudLinux license so this may not be accessible to everyone.

  2. After receiving a ticket about this today, I spent some time researching the issue to see if I could find a way to make this work. As a result, I've published the following guide that outlines how to make use of the ImageMagick package provided by the Remi Repository which is compiled with webp support. Due to the fact that cPanel is not developed or tested in the context of having the Remi Repository installed, we're not able to provide support for making use of the guide, or issues that may stem from its use. However, we'd like to offer the guide as a courtesy for those systems administrators who are interested nonetheless. This guide also includes a link to a rudimentary PHP script that I wrote for testing and verifying image support for webp and other common formats.

https://support.cpanel.net/hc/en-us/articles/4403506784919-How-to-enable-the-webp-image-format-for-use-with-ImageMagick-on-cPanel

  1. The third option would be to manually compile ImageMagick and reinstall the PECL extension for use with your custom ImageMagick installation as is mentioned in other answers here.
  • Austin Lowery, Technial Analyst II, cPanel
Nellanellda answered 1/7, 2021 at 1:39 Comment(2)
It would be nice that cPanel allow PHP stack from remi, thus avoiding to rebuild anything. Also notice that the imagick extension is available in 2 variants, one using ImageMagick6, other using ImageMagick7Interracial
Hello Remi! Thanks for the reply! I went ahead and added your suggestion as a feature request here: features.cpanel.net/topic/… It may take some time for that link to be reviewed and activated by our community team though. Once active, please feel free to add your own use case/perspective as well and share with others who are interested! On a personal note, I'd like to thank you for your continued hard work over the years. I've very much enjoyed the benefits of the Remi Repo in my personal computing!Nellanellda
C
1

Compile ImageMagick from source on CentOS 7 with .webp support

yum -y remove ImageMagick* && cd /root && rm -f ImageMagick.tar.gz && yum -y install bzip2-devel libtiff-devel giflib-devel ghostscript-devel libwmf-devel jasper-devel libtool-ltdl-devel libXext-devel libXt-devel OpenEXR-devel libwebp-devel rpmdevtool libtool-ltdl-devel ImageMagick-devel freetype-devel ghostscript-devel libwmf-devel jasper-devel lcms-devel bzip2-devel librsvg librsvg2 librsvg2* liblpr-1 liblqr-1-devel libtool-ltdl-devel autotrace-devel freetype +bytecode graphviz gs wmf jbig jpeg2 lcms jpeg libjpeg libjpeg-devel libtiff && cd /tmp && wget http://mirror.checkdomain.de/imagemagick/ImageMagick.tar.gz && tar xvfz ImageMagick.tar.gz && cd ImageMagick* && ./configure --prefix=/usr --with-rsvg=yes --with-wmf=yes --with-png=yes --with-libtiff=yes --with-tiff=yes --with-jpeg=yes --with-jp2=yes --with-freetype=yes && make && make install && ldconfig /usr/local/lib
Columbarium answered 15/6, 2021 at 20:7 Comment(0)
D
1

@be3 Thank you for this. I have made a small change to this since I couldn't execute ./configure from the /tmp folder I move it to the /root folder for execution.

yum -y remove ImageMagick* && cd /root && rm -f ImageMagick.tar.gz && yum -y install bzip2-devel libtiff-devel giflib-devel ghostscript-devel libwmf-devel jasper-devel libtool-ltdl-devel libXext-devel libXt-devel OpenEXR-devel libwebp-devel rpmdevtool libtool-ltdl-devel ImageMagick-devel freetype-devel ghostscript-devel libwmf-devel jasper-devel lcms-devel bzip2-devel librsvg librsvg2 librsvg2* liblpr-1 liblqr-1-devel libtool-ltdl-devel autotrace-devel freetype +bytecode graphviz gs wmf jbig jpeg2 lcms jpeg libjpeg libjpeg-devel libtiff && cd /tmp && wget http://mirror.checkdomain.de/imagemagick/ImageMagick.tar.gz && tar xvfz ImageMagick.tar.gz && cd / && cp -r /tmp/ImageMagick-7.1.0-2 / && cd ImageMagick* && ./configure --prefix=/usr --with-rsvg=yes --with-wmf=yes --with-png=yes --with-libtiff=yes --with-tiff=yes --with-jpeg=yes --with-jp2=yes --with-freetype=yes --with-webp=yes && make && make install && ldconfig /usr/local/lib
Diplopod answered 28/6, 2021 at 16:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.