Retunr WP_Error from wp_crop_image() and image_resize(). Props mdwaffe. fixes #9922

git-svn-id: http://svn.automattic.com/wordpress/trunk@12524 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
ryan 2009-12-23 18:39:31 +00:00
parent 810bf31f83
commit 9b6bd6bf87
3 changed files with 10 additions and 4 deletions

View File

@ -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']);

View File

@ -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 );

View File

@ -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 )