Index: wp-admin/custom-header.php =================================================================== --- wp-admin/custom-header.php (revision 20778) +++ wp-admin/custom-header.php (working copy) @@ -788,7 +788,11 @@ - +
@@ -867,12 +871,16 @@ else $dst_width = get_theme_support( 'custom-header', 'width' ); - $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height ); - if ( ! $cropped || is_wp_error( $cropped ) ) - wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); + if ( !isset( $_POST['skip-cropping'] ) ) { + $cropped = wp_crop_image( $attachment_id, (int) $_POST['x1'], (int) $_POST['y1'], (int) $_POST['width'], (int) $_POST['height'], $dst_width, $dst_height ); + if ( ! $cropped || is_wp_error( $cropped ) ) + wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) ); + } else { + $cropped = get_attached_file( $attachment_id ); + } $cropped = apply_filters('wp_create_file_in_uploads', $cropped, $attachment_id); // For replication - $is_cropped = ( get_attached_file( $attachment_id ) != $cropped ); + $is_cropped = ( !isset( $_POST['skip-cropping'] ) && ( get_attached_file( $attachment_id ) != $cropped ) ); $parent = get_post($attachment_id); $parent_url = $parent->guid; Index: wp-admin/includes/image.php =================================================================== --- wp-admin/includes/image.php (revision 20778) +++ wp-admin/includes/image.php (working copy) @@ -44,9 +44,24 @@ * @return string|WP_Error|false New filepath on success, WP_Error or false on failure. */ function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) { - if ( 0 == $src_x && 0 == $src_y && $src_w == $dst_w && $src_h == $dst_h ) - return ( is_numeric( $src ) ) ? get_attached_file( $src ) : $src; + if ( 0 == $src_x && 0 == $src_y && $src_w == $dst_w && $src_h == $dst_h ) { + // No cropping, just copy the file + if ( is_numeric( $src ) ) { + $src_file = get_attached_file( $src ); + if ( ! file_exists( $src_file ) ) + $src_file = _load_image_file( $src ); + } else { + $src_file = $src; + } + if ( $src_file ) { + $dst_file = str_replace( basename( $src_file ), 'cropped-' . basename( $src_file ), $src_file ); + return ( copy( $src_file, $dst_file ) ) ? $dst_file : false; + } else { + return false; + } + } + if ( is_numeric( $src ) ) { // Handle int as attachment ID $src_file = get_attached_file( $src ); if ( ! file_exists( $src_file ) ) { @@ -364,7 +379,17 @@ return apply_filters('file_is_displayable_image', $result, $path); } -function load_image_to_edit($post_id, $mime_type, $size = 'full') { +/** + * Attempt to load an attachment from URL (for replication plugins). + * + * @since 3.4.0 + * @access private + * + * @param string $post_id Attachment post ID. + * @param string $size Optional. Image size, defaults to 'full'. + * @return string|false Local file path on success, false on failure. + */ +function _load_image_file( $post_id, $size = 'full' ) { $filepath = get_attached_file($post_id); if ( $filepath && file_exists($filepath) ) { @@ -376,9 +401,25 @@ } $filepath = apply_filters('load_image_to_edit_path', $filepath, $post_id, $size); - if ( empty($filepath) ) + if ( empty( $filepath ) ) return false; +} +/** + * Load an image resource for editing. + * + * @since 2.9.0 + * + * @param string $post_id Attachment post ID. + * @param string $mime_type Image mime type. + * @param string $size Optional. Image size, defaults to 'full'. + * @return resource|false The resulting image resource on success, false on failure. + */ +function load_image_to_edit( $post_id, $mime_type, $size = 'full' ) { + $filepath = _load_image_file( $post_id, $size ); + if ( empty( $filepath ) ) + return false; + switch ( $mime_type ) { case 'image/jpeg': $image = imagecreatefromjpeg($filepath);