Try this code in function.php I hope this help.
add_action( 'rest_api_init', 'set_image_dimension_limit' );
function set_image_dimension_limit() {
add_filter( 'wp_handle_upload_prefilter', function( $file ) {
$mimes = array( 'image/jpeg', 'image/png', 'image/gif' );
if( !in_array( $file['type'], $mimes ) )
return $file;
$img = getimagesize( $file['tmp_name'] );
$maximum = array( 'width' => 500, 'height' => 700 );
if ( $img[0] > $maximum['width'] )
$file['error'] =
'Image too large. Maximum width is '
. $maximum['width']
. 'px. Uploaded image width is '
. $img[0] . 'px';
elseif ( $img[1] > $maximum['height'] )
$file['error'] =
'Image too large. Maximum height is '
. $maximum['height']
. 'px. Uploaded image height is '
. $img[1] . 'px';
return $file;
} );
}