4

I have a client who allows customers to upload large files to manipulate for printing. The site's using Imagick to handle the image, however, when trying to set the max width and height, it wont go any higher than 16000. For example:

// This sets the max width to 20000px
php > Imagick::setResourceLimit(9, 20000);
php > echo $image->getResourceLimit(9);
16000

php > Imagick::setResourceLimit(9, 15000);
php > echo $image->getResourceLimit(9);
15000

Is this a limitation of the library or is there something else I need to be configuring?

Jam3sn
  • 1,077
  • 4
  • 17
  • 35

1 Answers1

4

You need to find your policy.xml for ImageMagick and uncomment and set up the lines that look like this:

<!-- <policy domain="resource" name="memory" value="2GiB"/> -->
<!-- <policy domain="resource" name="width" value="10KP"/> -->
<!-- <policy domain="resource" name="height" value="10KP"/> -->

You should be able to find the file with:

identify -list configure | grep CONFIGURE_PATH

Sample Output

CONFIGURE_PATH /usr/local/Cellar/imagemagick/7.0.8-10/etc/ImageMagick-7/

then append policy.xml to the end of that. So mine is:

/usr/local/Cellar/imagemagick/7.0.8-10/etc/ImageMagick-7/policy.xml

If, for some reason you cannot find the policy.xml file by the method above, you can search for it the long (slower) way with:

find  /usr  /opt /  -name policy.xml
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thanks Mark. I've tried that, but it returns `Command 'identify' not found` and then suggests some imagemagick packages to install. However it's definitely installed and is listed in `phpinfo()`. I've also ran `apt-cache policy php-imagick` which has returned `php-imagick: Installed: 3.4.3-3+ubuntu18.04.1+deb.sury.org+1`, so it's installed, any ideas? – Jam3sn Aug 29 '18 at 11:03
  • If you have v7 of **ImageMagick** installed and you didn't tick the box marked *"Install legacy commands"* when you installed, you need to prefix **ImageMagick** commands with the word `magick`, so try `magick identify ...` – Mark Setchell Aug 29 '18 at 11:36
  • Alternatively, you can find the file the long way with `find /usr /opt / -name policy.xml` – Mark Setchell Aug 29 '18 at 11:38
  • Found it! Thanks Mark! – Jam3sn Aug 29 '18 at 12:02