From 7ccd64fbe75205fef78dd86585975a1242da6025 Mon Sep 17 00:00:00 2001 From: Ryan Boren Date: Wed, 23 Dec 2009 18:39:31 +0000 Subject: [PATCH] Retunr WP_Error from wp_crop_image() and image_resize(). Props mdwaffe. fixes #9922 git-svn-id: https://develop.svn.wordpress.org/trunk@12524 602fd350-edb4-49c9-b593-d223f7449a82 --- wp-admin/custom-header.php | 6 ++++++ wp-admin/includes/image.php | 6 +++--- wp-includes/media.php | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/wp-admin/custom-header.php b/wp-admin/custom-header.php index fb07fe8013..6931bbe558 100644 --- a/wp-admin/custom-header.php +++ b/wp-admin/custom-header.php @@ -360,6 +360,9 @@ class Custom_Image_Header { } elseif ( $width > HEADER_IMAGE_WIDTH ) { $oitar = $width / HEADER_IMAGE_WIDTH; $image = wp_crop_image($file, 0, 0, $width, $height, HEADER_IMAGE_WIDTH, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file)); + if ( is_wp_error( $image ) ) + wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); + $image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication $url = str_replace(basename($url), basename($image), $url); @@ -414,6 +417,9 @@ class Custom_Image_Header { $original = get_attached_file( $_POST['attachment_id'] ); $cropped = wp_crop_image($_POST['attachment_id'], $_POST['x1'], $_POST['y1'], $_POST['width'], $_POST['height'], HEADER_IMAGE_WIDTH, HEADER_IMAGE_HEIGHT); + if ( is_wp_error( $cropped ) ) + wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); + $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication $parent = get_post($_POST['attachment_id']); diff --git a/wp-admin/includes/image.php b/wp-admin/includes/image.php index 903bd5fe17..f1cd972f34 100644 --- a/wp-admin/includes/image.php +++ b/wp-admin/includes/image.php @@ -38,7 +38,7 @@ function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) { * @param int $dst_h The destination height. * @param int $src_abs Optional. If the source crop points are absolute. * @param string $dst_file Optional. The destination file to write to. - * @return string New filepath on success, String error message on failure. + * @return string|WP_Error|false New filepath on success, WP_Error or false on failure. */ function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { if ( is_numeric( $src_file ) ) // Handle int as attachment ID @@ -46,8 +46,8 @@ function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_ $src = wp_load_image( $src_file ); - if ( !is_resource( $src )) - return $src; + if ( !is_resource( $src ) ) + return new WP_Error( 'error_loading_image', $src, $src_file ); $dst = wp_imagecreatetruecolor( $dst_w, $dst_h ); diff --git a/wp-includes/media.php b/wp-includes/media.php index 8f0bf3aaa1..318a6350f0 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -355,7 +355,7 @@ function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $de $image = wp_load_image( $file ); if ( !is_resource( $image ) ) - return new WP_Error('error_loading_image', $image); + return new WP_Error( 'error_loading_image', $image, $file ); $size = @getimagesize( $file ); if ( !$size )