php - ImageMagick cache resource exhaustedGet the solution ↓↓↓
I use PHP and Imagick extension for resize a photo (about 5000x7000):
$img = new Imagick($fn); $img->thumbnailImage($width, 0);
It works for
$width is 800, 900 ... 1300,
but it crashes for 1400 and 1600:
cache resources exhausted /app/photo.jpg' @ error/cache.c/OpenPixelCache/4083.
I assumed it depends on the width and the result image size. And googling for the error text confirmed my guesses. They advise to increase memory limits in ImageMagick config.
But! I tried to create image with the width is 2000 and it worked correctly!
1400, 1600, 1800 - fail. 1900, 2000, 2100... - success.
Increase the amount of resources that ImageMagick may use. You can control how many resources ImageMagick may use by editing the
policy.xml file. See the documentation on security policy.
On my (Debian Linux) system the configuration is located at
/etc/ImageMagick-6/policy.xml. See here for different locations on various operating systems.
I changed the following settings to
2GiB to get rid of the error, you may need different ones, depending on your needs and system resources. Take a look at the documentation.
<policy domain="resource" name="memory" value="2GiB"/> <policy domain="resource" name="map" value="2GiB"/>
People are also looking for solutions of the problem: call to a member function getclientoriginalname() on null
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.