diff --git a/wp-admin/custom-header.php b/wp-admin/custom-header.php index 98030012c..b7817f1a8 100644 --- a/wp-admin/custom-header.php +++ b/wp-admin/custom-header.php @@ -700,7 +700,14 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> extract($this->step_2_manage_upload()); } - list($width, $height, $type, $attr) = getimagesize( $file ); + if ( file_exists( $file ) ) { + list( $width, $height, $type, $attr ) = getimagesize( $file ); + } else { + $data = wp_get_attachment_metadata( $id ); + $height = $data[ 'height' ]; + $width = $data[ 'width' ]; + unset( $data ); + } $max_width = 0; // For flex, limit size of image displayed to 1500px unless theme says otherwise @@ -716,7 +723,8 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> && $width == get_theme_support( 'custom-header', 'width' ) && $height == get_theme_support( 'custom-header', 'height' ) ) { // Add the meta-data - wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); + if ( file_exists( $file ) ) + wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $file ) ); update_post_meta( $id, '_wp_attachment_is_custom_header', get_option('stylesheet' ) ); set_theme_mod('header_image', esc_url($url)); @@ -724,7 +732,7 @@ wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> return $this->finished(); } elseif ( $width > $max_width ) { $oitar = $width / $max_width; - $image = wp_crop_image($file, 0, 0, $width, $height, $max_width, $height / $oitar, false, str_replace(basename($file), 'midsize-'.basename($file), $file)); + $image = wp_crop_image($id, 0, 0, $width, $height, $max_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' ) ); diff --git a/wp-admin/includes/image-edit.php b/wp-admin/includes/image-edit.php index 0d4605489..d2d6dc2cf 100644 --- a/wp-admin/includes/image-edit.php +++ b/wp-admin/includes/image-edit.php @@ -197,45 +197,6 @@ function wp_image_editor($post_id, $msg = false) { post_mime_type, 'full' ); + } else { + $src = wp_load_image( $src_file ); + } + } else { + $src = wp_load_image( $src_file ); + } - $src = wp_load_image( $src_file ); - - if ( !is_resource( $src ) ) + if ( ! is_resource( $src ) ) return new WP_Error( 'error_loading_image', $src, $src_file ); $dst = wp_imagecreatetruecolor( $dst_w, $dst_h ); @@ -59,7 +68,7 @@ function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_ $src_h -= $src_y; } - if (function_exists('imageantialias')) + if ( function_exists( 'imageantialias' ) ) imageantialias( $dst, true ); imagecopyresampled( $dst, $src, 0, 0, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h ); @@ -71,6 +80,10 @@ function wp_crop_image( $src_file, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_ $dst_file = preg_replace( '/\\.[^\\.]+$/', '.jpg', $dst_file ); + // The directory containing the original file may no longer exist when + // using a replication plugin. + wp_mkdir_p( dirname( $dst_file ) ); + if ( imagejpeg( $dst, $dst_file, apply_filters( 'jpeg_quality', 90, 'wp_crop_image' ) ) ) return $dst_file; else @@ -339,3 +352,42 @@ function file_is_displayable_image($path) { return apply_filters('file_is_displayable_image', $result, $path); } + +function load_image_to_edit($post_id, $mime_type, $size = 'full') { + $filepath = get_attached_file($post_id); + + if ( $filepath && file_exists($filepath) ) { + if ( 'full' != $size && ( $data = image_get_intermediate_size($post_id, $size) ) ) { + $filepath = apply_filters('load_image_to_edit_filesystempath', path_join( dirname($filepath), $data['file'] ), $post_id, $size); + } + } elseif ( function_exists('fopen') && function_exists('ini_get') && true == ini_get('allow_url_fopen') ) { + $filepath = apply_filters('load_image_to_edit_attachmenturl', wp_get_attachment_url($post_id) , $post_id, $size); + } + + $filepath = apply_filters('load_image_to_edit_path', $filepath, $post_id, $size); + if ( empty($filepath) ) + return false; + + switch ( $mime_type ) { + case 'image/jpeg': + $image = imagecreatefromjpeg($filepath); + break; + case 'image/png': + $image = imagecreatefrompng($filepath); + break; + case 'image/gif': + $image = imagecreatefromgif($filepath); + break; + default: + $image = false; + break; + } + if ( is_resource($image) ) { + $image = apply_filters('load_image_to_edit', $image, $post_id, $size); + if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) { + imagealphablending($image, false); + imagesavealpha($image, true); + } + } + return $image; +}