Ticket #31050: 31050.8.patch
File 31050.8.patch, 9.8 KB (added by , 9 years ago) |
---|
-
src/wp-admin/includes/image.php
78 78 79 79 $metadata = array(); 80 80 $support = false; 81 if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) { 81 $mime_type = get_post_mime_type( $attachment ); 82 83 /** 84 * Filter attachment mime-types that support thumbnail fallback. 85 * 86 * @since 4.5.0 87 * 88 * @param array $mime_types An array of mime-types. 89 */ 90 $attachment_fallback_mimetypes = apply_filters( 'attachment_fallback_mimetypes', array( 'application/pdf' ) ); 91 92 if ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image($file) ) { 82 93 $imagesize = getimagesize( $file ); 83 94 $metadata['width'] = $imagesize[0]; 84 95 $metadata['height'] = $imagesize[1]; … … 192 203 } 193 204 } 194 205 } 206 // Check to see if we support a fallback thumbnail for this mime-type. 207 else if ( in_array( $mime_type, $attachment_fallback_mimetypes ) ) { 208 $editor = wp_get_image_editor( $file ); 209 $sizes = array( 210 'thumbnail' => array( 211 'width' => get_option( "thumbnail_size_w" ), 212 'height' => get_option( "thumbnail_size_h" ), 213 'crop' => get_option( "thumbnail_crop" ) 214 ) 215 ); 195 216 217 if ( ! is_wp_error( $editor ) ) { // No support for this type of file 218 $uploaded = $editor->save( $file . '.jpg' ); 219 unset( $uploaded['path'] ); 220 221 if ( ! is_wp_error( $uploaded ) ) { 222 $metadata['sizes'] = $editor->multi_resize( $sizes ); 223 $metadata['sizes']['full'] = $uploaded; 224 } 225 } 226 } 227 196 228 // Remove the blob of binary data from the array. 197 229 if ( $metadata ) { 198 230 unset( $metadata['image']['data'] ); -
src/wp-admin/includes/media.php
2753 2753 2754 2754 echo wp_video_shortcode( $attr ); 2755 2755 2756 else : 2757 $image = wp_get_attachment_image( $attachment_id, 'full', false, array( 'style' => 'max-width:100%' ) ); 2758 2759 if ( $image ) { 2760 echo '<div class="wp_attachment_image wp-clearfix" id="media-head-' . $attachment_id . '">'; 2761 echo '<p id="thumbnail-head-<?php echo $attachment_id; ?>">' . $image . '</p>'; 2762 echo '</div>'; 2763 } 2764 2756 2765 endif; ?> 2757 2766 </div> 2758 2767 <div class="wp_attachment_details edit-form-section"> -
src/wp-includes/media-template.php
290 290 <div class="thumbnail thumbnail-{{ data.type }}"> 291 291 <# if ( data.uploading ) { #> 292 292 <div class="media-progress-bar"><div></div></div> 293 <# } else if ( 'image' === data.type &&data.sizes && data.sizes.large ) { #>293 <# } else if ( data.sizes && data.sizes.large ) { #> 294 294 <img class="details-image" src="{{ data.sizes.large.url }}" draggable="false" alt="" /> 295 <# } else if ( 'image' === data.type &&data.sizes && data.sizes.full ) { #>295 <# } else if ( data.sizes && data.sizes.full ) { #> 296 296 <img class="details-image" src="{{ data.sizes.full.url }}" draggable="false" alt="" /> 297 297 <# } else if ( -1 === jQuery.inArray( data.type, [ 'audio', 'video' ] ) ) { #> 298 298 <img class="details-image icon" src="{{ data.icon }}" draggable="false" alt="" /> … … 454 454 <div class="centered"> 455 455 <# if ( data.image && data.image.src && data.image.src !== data.icon ) { #> 456 456 <img src="{{ data.image.src }}" class="thumbnail" draggable="false" alt="" /> 457 <# } else if ( data.sizes && data.sizes.full ) { #> 458 <img src="{{ data.sizes.full.url }}" class="thumbnail" draggable="false" alt="" /> 457 459 <# } else { #> 458 460 <img src="{{ data.icon }}" class="icon" draggable="false" alt="" /> 459 461 <# } #> -
src/wp-includes/media.php
163 163 * the image is an intermediate size. False on failure. 164 164 */ 165 165 function image_downsize( $id, $size = 'medium' ) { 166 $is_image = wp_attachment_is_image( $id ); 166 167 167 if ( !wp_attachment_is_image($id) ) 168 return false; 169 170 /** 171 * Filter whether to preempt the output of image_downsize(). 172 * 173 * Passing a truthy value to the filter will effectively short-circuit 174 * down-sizing the image, returning that value as output instead. 175 * 176 * @since 2.5.0 177 * 178 * @param bool $downsize Whether to short-circuit the image downsize. Default false. 179 * @param int $id Attachment ID for image. 180 * @param array|string $size Size of image. Image size or array of width and height values (in that order). 181 * Default 'medium'. 182 */ 183 if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) { 184 return $out; 168 if ( $is_image ) { 169 /** 170 * Filter whether to preempt the output of image_downsize(). 171 * 172 * Passing a truthy value to the filter will effectively short-circuit 173 * down-sizing the image, returning that value as output instead. 174 * 175 * @since 2.5.0 176 * 177 * @param bool $downsize Whether to short-circuit the image downsize. Default false. 178 * @param int $id Attachment ID for image. 179 * @param array|string $size Size of image. Image size or array of width and height values (in that order). 180 * Default 'medium'. 181 */ 182 if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) { 183 return $out; 184 } 185 185 } 186 186 187 $meta = wp_get_attachment_metadata($id); 188 187 189 $img_url = wp_get_attachment_url($id); 188 $meta = wp_get_attachment_metadata($id);189 190 $width = $height = 0; 190 191 $is_intermediate = false; 191 192 $img_url_basename = wp_basename($img_url); 192 193 194 if ( ! $is_image && ! empty( $meta['sizes'] ) ) { 195 $img_url = str_replace( $img_url_basename, $meta['sizes']['full']['file'], $img_url ); 196 $img_url_basename = $meta['sizes']['full']['file']; 197 $width = $meta['sizes']['full']['width']; 198 $height = $meta['sizes']['full']['height']; 199 } 200 193 201 // try for a new style intermediate size 194 202 if ( $intermediate = image_get_intermediate_size($id, $size) ) { 195 203 $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url); … … 206 214 $is_intermediate = true; 207 215 } 208 216 } 217 209 218 if ( !$width && !$height && isset( $meta['width'], $meta['height'] ) ) { 210 219 // any other type: use the real image 211 220 $width = $meta['width']; … … 637 646 if ( is_array($size) && !empty($imagedata['sizes']) ) { 638 647 $candidates = array(); 639 648 649 if ( ! isset( $imagedata['file'] ) && isset( $imagedata['sizes']['full'] ) ) { 650 $imagedata['height'] = $imagedata['sizes']['full']['height']; 651 $imagedata['width'] = $imagedata['sizes']['full']['width']; 652 } 653 640 654 foreach ( $imagedata['sizes'] as $_size => $data ) { 641 655 // If there's an exact match to an existing image size, short circuit. 642 656 if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) { … … 682 696 683 697 $data = $imagedata['sizes'][$size]; 684 698 // include the full filesystem path of the intermediate file 685 if ( empty($data['path']) && ! empty($data['file']) ) {699 if ( empty($data['path']) && ! empty($data['file']) && ! empty($imagedata['file'] ) ) { 686 700 $file_url = wp_get_attachment_url($post_id); 687 701 $data['path'] = path_join( dirname($imagedata['file']), $data['file'] ); 688 702 $data['url'] = path_join( dirname($file_url), $data['file'] ); … … 751 765 function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) { 752 766 // get a thumbnail or intermediate image if there is one 753 767 $image = image_downsize( $attachment_id, $size ); 768 754 769 if ( ! $image ) { 755 770 $src = false; 756 771 … … 985 1000 */ 986 1001 $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id ); 987 1002 988 if ( empty( $image_meta[' sizes'] ) ) {1003 if ( empty( $image_meta['file'] ) || empty( $image_meta['sizes'] ) ) { 989 1004 return false; 990 1005 } 991 1006 … … 3069 3084 if ( current_user_can( 'delete_post', $attachment->ID ) ) 3070 3085 $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); 3071 3086 3072 if ( $meta && 'image' === $type) {3087 if ( $meta && ! empty($meta['sizes']) ) { 3073 3088 $sizes = array(); 3074 3089 3075 3090 /** This filter is documented in wp-admin/includes/media.php */ … … 3117 3132 } 3118 3133 } 3119 3134 3120 $sizes['full'] = array( 'url' => $attachment_url ); 3135 if ( 'image' === $type ) { 3136 $sizes['full'] = array( 'url' => $attachment_url ); 3121 3137 3122 if ( isset( $meta['height'], $meta['width'] ) ) { 3123 $sizes['full']['height'] = $meta['height']; 3124 $sizes['full']['width'] = $meta['width']; 3125 $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape'; 3138 if ( isset( $meta['height'], $meta['width'] ) ) { 3139 $sizes['full']['height'] = $meta['height']; 3140 $sizes['full']['width'] = $meta['width']; 3141 $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape'; 3142 } 3143 3144 array_merge( $response, $sizes['full'] ); 3126 3145 } 3146 else if( $meta['sizes']['full']['file'] ) { 3147 $sizes['full'] = array( 3148 'url' => $base_url . $meta['sizes']['full']['file'], 3149 'height' => $meta['sizes']['full']['height'], 3150 'width' => $meta['sizes']['full']['width'], 3151 'orientation' => $meta['sizes']['full']['height'] < $meta['sizes']['full']['width'] ? 'portrait' : 'landscape' 3152 ); 3153 } 3127 3154 3128 $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); 3129 } elseif ( $meta && 'video' === $type ) { 3155 $response = array_merge( $response, array( 'sizes' => $sizes ) ); 3156 } 3157 3158 if ( $meta && 'video' === $type ) { 3130 3159 if ( isset( $meta['width'] ) ) 3131 3160 $response['width'] = (int) $meta['width']; 3132 3161 if ( isset( $meta['height'] ) )