php - ImageMagick cache resource exhausted
Get 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.
I'm lost.
Answer
Solution:
Increase the amount of resources that ImageMagick may use. You can control how many resources ImageMagick may use by editing thepolicy.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 to2GiB
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"/>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: 403 this action is unauthorized.
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.
Similar questions
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.