The Problem
When uploading large images, WordPress uses ImageMagick (via PHP's Imagick extension) to create thumbnails. If the image is too large or the server has insufficient memory, ImageMagick fails with a memory exhausted error.
Symptoms
- Image upload fails with "Post-processing of the image failed"
- Large images (over 5MB) fail to upload
- Error appears only for certain image files
- Thumbnails are not generated for uploaded images
- Server logs show ImageMagick memory errors
Real Error Message
``` Post-processing of the image failed likely because the server is busy or does not have enough resources. Uploading a smaller image may help.
Suggested maximum is 2500 pixels.
[ImageMagick error] allocate.cache: unable to extend cache 'No space left on device' @ error/cache.c/OpenPixelCache/3603 ```
How to Fix It
Fix 1: Increase PHP Memory Limit
// wp-config.php
define('WP_MEMORY_LIMIT', '256M');
define('WP_MAX_MEMORY_LIMIT', '512M');# php.ini
memory_limit = 512MFix 2: Increase ImageMagick Resource Limits
# /etc/ImageMagick-6/policy.xml
<policymap>
<policy domain="resource" name="memory" value="2GiB"/>
<policy domain="resource" name="map" value="4GiB"/>
<policy domain="resource" name="width" value="16KP"/>
<policy domain="resource" name="height" value="16KP"/>
<policy domain="resource" name="disk" value="8GiB"/>
</policymap>Fix 3: Use GD Instead of ImageMagick
// Add to theme's functions.php
add_filter('wp_image_editors', function($editors) {
return ['WP_Image_Editor_GD']; // Use GD instead of ImageMagick
});GD uses less memory but supports fewer image formats.
Fix 4: Compress Images Before Upload
```bash # Compress with ImageMagick before uploading convert large-photo.jpg -quality 82 -resize 2500x compressed.jpg
# Or use TinyPNG API curl -X POST --user api:YOUR_KEY \ --data-binary @large-photo.jpg \ https://api.tinify.com/shrink > compressed.jpg ```
Fix 5: Set Maximum Image Dimensions
// functions.php
add_filter('big_image_size_threshold', function($threshold) {
return 2500; // Pixels (default is 2560)
});Images larger than this threshold are automatically scaled down.
Fix 6: Clear ImageMagick Cache
```bash # Clear the temp directory sudo rm -rf /tmp/magick-* sudo rm -rf /tmp/imagick-*
# Check disk space df -h /tmp ```
Fix 7: Debug Image Editor Selection
// functions.php - Log which editor is being used
add_filter('wp_image_editors', function($editors) {
error_log('Image editors available: ' . print_r($editors, true));
return $editors;
});