From the Log

How to fix ‘The server cannot process the image’ error in WordPress

Many WordPress users have reported seeing the following error message when uploading images to the Media Library:

The server cannot process the image. This can happen if the server is busy or does not have enough resources to complete the task. Uploading a smaller image may help. Suggested maximum size is 2560 pixels.

Typically, users report that this error starts appearing at random — usually in systems running PHP 7.4 and WordPress 5.5 or above.

From what we can see, there are two possible reasons that this error occurs. The first is that the server on which WordPress is installed does, indeed, “not have enough resources to complete the task.” The second is that the server on which WordPress is installed is taking longer to process the task than a proxy server sitting in front of it expects.

Insufficient Resources

If a lack of memory is your issue, you should start by increasing your PHP limits in both WordPressĀ  and on your server. You can do this in WordPress by adding the following line to your wp-config.php file (this example increases the memory limit to 256MB, but you can set your own):

define('WP_MEMORY_LIMIT', '256M');

You can do the the same thing on your server by adding the following to php.ini:

memory_limit = 256M;

If you do not have direct access to your server, you can ask your host to do this for you.

šŸš© This is not the same thing as increasing the maximum upload size, although you obviously need to ensure that your PHP memory limits are equal to, or larger than, that value.

Proxy Timeouts

If this does not work, you may have a client-side timeout issue. Usually, this is caused because a proxy server that is sitting in front of WordPress (e.g.: HAProxy, Varnish, or Squid) has a set of timeout values that trigger before WordPress’s media library has finished processing an upload.

When you upload a huge image to WordPress, WordPress has to perform a set of tasks before it makes it available to you in the library — tasks such as cutting the image into the various sizes that are specified in your theme’s functions.php file, applying any compression plugins you may have configured, and then running any offloading or backups you have installed. If WordPress takes longer to do this than your proxy server expects, the proxy server will drop the connection. Because it is unaware that it has a proxy server in front of it, WordPress will interpret this dropped connection as having come directly from the client (if you’re using Nginx, this will show up in the logs as a 499) and throw its ‘The server cannot process the image’ error.

To fix this, you can alter the timeout threshold so that it is greater than the time WordPress takes to process large images. In HAProxy, for example, this would involve editing the timeout server variable within your backend block.

Red Herrings

(1) Many users seem to have noticed that turning on certain plugins correlates with the appearance of this error. Usually, though, those plugins are related, but they are not its cause. Instead, they are simply adding more processing time — and/or more memory usage — to the media upload process.

(2) A number of advice sites recommend fixing the error by switching out the GD Library package on your server for the ImageMagick package. Most, however, seem not to know why this sometimes works, which is not because there is anything intrinsically wrong with GD, but because ImageMagick is more efficient, and because it is therefore less likely to add more time or memory-use to the media upload process.