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
This commit is contained in:
parent
95ea3693b1
commit
7ccd64fbe7
@ -360,6 +360,9 @@ class Custom_Image_Header {
|
|||||||
} elseif ( $width > HEADER_IMAGE_WIDTH ) {
|
} elseif ( $width > HEADER_IMAGE_WIDTH ) {
|
||||||
$oitar = $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));
|
$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
|
$image = apply_filters('wp_create_file_in_uploads', $image, $id); // For replication
|
||||||
|
|
||||||
$url = str_replace(basename($url), basename($image), $url);
|
$url = str_replace(basename($url), basename($image), $url);
|
||||||
@ -414,6 +417,9 @@ class Custom_Image_Header {
|
|||||||
$original = get_attached_file( $_POST['attachment_id'] );
|
$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);
|
$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
|
$cropped = apply_filters('wp_create_file_in_uploads', $cropped, $_POST['attachment_id']); // For replication
|
||||||
|
|
||||||
$parent = get_post($_POST['attachment_id']);
|
$parent = get_post($_POST['attachment_id']);
|
||||||
|
@ -38,7 +38,7 @@ function wp_create_thumbnail( $file, $max_side, $deprecated = '' ) {
|
|||||||
* @param int $dst_h The destination height.
|
* @param int $dst_h The destination height.
|
||||||
* @param int $src_abs Optional. If the source crop points are absolute.
|
* @param int $src_abs Optional. If the source crop points are absolute.
|
||||||
* @param string $dst_file Optional. The destination file to write to.
|
* @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 ) {
|
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
|
if ( is_numeric( $src_file ) ) // Handle int as attachment ID
|
||||||
@ -47,7 +47,7 @@ function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_
|
|||||||
$src = wp_load_image( $src_file );
|
$src = wp_load_image( $src_file );
|
||||||
|
|
||||||
if ( !is_resource( $src ) )
|
if ( !is_resource( $src ) )
|
||||||
return $src;
|
return new WP_Error( 'error_loading_image', $src, $src_file );
|
||||||
|
|
||||||
$dst = wp_imagecreatetruecolor( $dst_w, $dst_h );
|
$dst = wp_imagecreatetruecolor( $dst_w, $dst_h );
|
||||||
|
|
||||||
|
@ -355,7 +355,7 @@ function image_resize( $file, $max_w, $max_h, $crop = false, $suffix = null, $de
|
|||||||
|
|
||||||
$image = wp_load_image( $file );
|
$image = wp_load_image( $file );
|
||||||
if ( !is_resource( $image ) )
|
if ( !is_resource( $image ) )
|
||||||
return new WP_Error('error_loading_image', $image);
|
return new WP_Error( 'error_loading_image', $image, $file );
|
||||||
|
|
||||||
$size = @getimagesize( $file );
|
$size = @getimagesize( $file );
|
||||||
if ( !$size )
|
if ( !$size )
|
||||||
|
Loading…
Reference in New Issue
Block a user