HTTP ERROR when uploading images in WordPress

When uploading an image via WordPress media library, one of the following errors appears:

Post-processing of the image failed. If this is a photo or a large image, please scale it down to 2500 pixels and upload it again

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

The following error might appear in the apache error log:


2023-02-24 15:12:58.644998 [NOTICE] [43985] [T0] [IP_ADDRESS:52826-H3:09E5BB-20#APVH_domain.xyz:lsapi] POST request in process stage, fail with 503
2023-02-24 15:12:58.645019 [NOTICE] [43985] [T0] [IP_ADDRESS:52826-H3:09E5BB-20#APVH_domain.xyz.ca:lsapi] oops! 503 Service Unavailable
2023-02-24 15:12:58.645023 [NOTICE] [43985] [T0] [IP_ADDRESS:52826-H3:09E5BB-20#APVH_domain.xyz:lsapi] Content len: 17878886, Request line: ‘POST /wp-admin/async-upload.php HTTP/1.1’


Solution:

You can force WordPress Upload to use GD by adding the below lines to your theme’s function.php file.

function wpb_image_editor_default_to_gd( $editors ) {
    $gd_editor = 'WP_Image_Editor_GD';
    $editors = array_diff( $editors, array( $gd_editor ) );
    array_unshift( $editors, $gd_editor );
    return $editors;
}
add_filter( 'wp_image_editors', 'wpb_image_editor_default_to_gd' );