Project

General

Profile

Actions

"How to Install SVG Support for php-imagick Module for Better Compatibility"

Module php-imagick in this instance has no SVG support. For better compatibility it is recommended to install it.

To enable SVG support in Imagick, you will need to install the librsvg2-bin package, which provides the necessary library for rendering SVG files.

You can install it on Ubuntu by running the following command:

sudo apt-get install librsvg2-bin

After installing the package, you need to configure Imagick to use the librsvg2 library by updating the policy.xml file. You can do this by editing the file /etc/ImageMagick-6/policy.xml or /etc/ImageMagick-*/policy.xml if you have a newer version of ImageMagick installed.

nano /etc/ImageMagick-6/policy.xml

Find the following line:

<!-- <policymap> -->

***.....

Add this part under this line...

 <!-- enable SVG support -->
  <policy domain="coder" rights="none" pattern="SVG" />

</policymap>

This adds the line <policy domain="coder" rights="none" pattern="SVG" /> to enable SVG support. Save this as a file and replace the contents of your current policy map XML

you will need to restart Apache for the changes to take effect. You can do this with the following command:

sudo systemctl restart apache2

If you have restarted your web server and updated the Imagick configuration file as suggested, and it is still not working, then there might be a different issue.

You can try to verify if the Imagick module was compiled with SVG support by running the following command:

php -r "echo (new Imagick())->queryFormats('SVG') ? 'SVG supported' : 'SVG not supported';" 

If it returns "SVG not supported", then it means that the Imagick module was not compiled with SVG support. In that case, you might need to recompile the Imagick module with SVG support or install a different version of the Imagick module that has SVG support.

First, try to install the necessary libraries and dependencies for ImageMagick to support SVG. Depending on your operating system, the commands to install these libraries might be different. Here are some examples:

For Debian/Ubuntu:

sudo apt-get install libmagickcore-6.q16-6-extra

After installing the necessary libraries and dependencies, restart your web server and check if SVG images are supported.

If SVG is still not supported, you may need to recompile ImageMagick from source with SVG support enabled. You can download the ImageMagick source code from the official website and follow the installation instructions provided in the documentation.


Here are the general steps for compiling ImageMagick from source with SVG support:

Download the latest source code from the official ImageMagick website: https://imagemagick.org/script/download.php

Extract the downloaded archive to a directory of your choice.

Install the required build tools, such as the GNU Compiler Collection (GCC), make, and automake. On Ubuntu or Debian-based systems, you can use the following command:

sudo apt-get install build-essential

Install the required libraries for SVG support, such as libxml2-dev, libcairo2-dev, and libpango1.0-dev. On Ubuntu or Debian-based systems, you can use the following command:

sudo apt-get install libxml2-dev libcairo2-dev libpango1.0-dev

Configure the ImageMagick build by running the following command from the directory where you extracted the source code:

./configure --with-modules --with-perl --with-xml=yes --with-pango=yes --with-cairo=yes --with-rsvg=yes

This command will enable support for various modules, Perl, XML, Pango, Cairo, and RSVG (the library that provides SVG support).

Build the ImageMagick binaries by running the following command:

make

Install ImageMagick by running the following command as root:

sudo make install

Finally, check that the SVG format is supported by running the following command:

convert -list format | grep SVG

If the SVG format is listed, then SVG support has been successfully enabled.

Note that the above steps may vary depending on your operating system and environment. It's also worth noting that compiling from source can be a complex process, and may require some troubleshooting if any issues arise.

Updated by Gareth Eaton 10 months ago · 7 revisions