Ticket #31050: 31050.4.patch
File 31050.4.patch, 7.7 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 $attachment_fallback_mimetypes = apply_filters( 'attachment_fallback_mimetypes', array( 'application/pdf', 'video/avi' ) ); 82 $mime_type = get_post_mime_type( $attachment ); 83 84 if ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image($file) ) { 82 85 $imagesize = getimagesize( $file ); 83 86 $metadata['width'] = $imagesize[0]; 84 87 $metadata['height'] = $imagesize[1]; … … 192 195 } 193 196 } 194 197 } 198 else if ( in_array( $mime_type, $attachment_fallback_mimetypes ) ) { 199 $editor = wp_get_image_editor( $file ); 200 $sizes = array( 201 'thumbnail' => array( 202 'width' => get_option( "thumbnail_size_w" ), 203 'height' => get_option( "thumbnail_size_h" ), 204 'crop' => get_option( "thumbnail_crop" ) 205 ) 206 ); 195 207 208 if ( ! is_wp_error( $editor ) ) { // No support for this type of file 209 $uploaded = $editor->save( $file . '.jpg' ); 210 211 if ( ! is_wp_error( $uploaded ) ) { 212 $metadata['width'] = $uploaded['width']; 213 $metadata['height'] = $uploaded['height']; 214 $metadata['file'] = _wp_relative_upload_path( dirname( $file ) . '/' . $uploaded['file'] ); 215 $metadata['sizes'] = $editor->multi_resize( $sizes ); 216 } 217 } 218 } 219 196 220 // Remove the blob of binary data from the array. 197 221 if ( $metadata ) { 198 222 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 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 } 186 187 $meta = wp_get_attachment_metadata($id); 188 189 if ( ! $meta || empty( $meta['sizes'] ) ) { 168 190 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-circuit174 * down-sizing the image, returning that value as output instead.175 *176 * @since 2.5.0177 *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;185 191 } 186 192 187 193 $img_url = wp_get_attachment_url($id); 188 $meta = wp_get_attachment_metadata($id);189 194 $width = $height = 0; 190 195 $is_intermediate = false; 191 196 $img_url_basename = wp_basename($img_url); 192 197 198 if ( ! $is_image ) { 199 $img_url = str_replace( $img_url_basename, wp_basename($meta['file']), $img_url ); 200 $img_url_basename = wp_basename($meta['file']); 201 } 202 193 203 // try for a new style intermediate size 194 204 if ( $intermediate = image_get_intermediate_size($id, $size) ) { 195 205 $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url); … … 206 216 $is_intermediate = true; 207 217 } 208 218 } 219 209 220 if ( !$width && !$height && isset( $meta['width'], $meta['height'] ) ) { 210 221 // any other type: use the real image 211 222 $width = $meta['width']; … … 1006 1017 */ 1007 1018 $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id ); 1008 1019 1009 if ( empty( $image_meta[' sizes'] ) ) {1020 if ( empty( $image_meta['file'] ) || empty( $image_meta['sizes'] ) ) { 1010 1021 return false; 1011 1022 } 1012 1023 … … 3090 3101 if ( current_user_can( 'delete_post', $attachment->ID ) ) 3091 3102 $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); 3092 3103 3093 if ( $meta && 'image' === $type) {3104 if ( $meta && ! empty($meta['sizes']) ) { 3094 3105 $sizes = array(); 3095 3106 3096 3107 /** This filter is documented in wp-admin/includes/media.php */ … … 3138 3149 } 3139 3150 } 3140 3151 3141 $sizes['full'] = array( 'url' => $attachment_url ); 3152 if ( 'image' === $type ) { 3153 $sizes['full'] = array( 'url' => $attachment_url ); 3154 } 3155 else { 3156 $sizes['full'] = array( 'url' => $base_url . wp_basename( $meta['file'] ) ); 3157 } 3142 3158 3143 3159 if ( isset( $meta['height'], $meta['width'] ) ) { 3144 3160 $sizes['full']['height'] = $meta['height']; … … 3147 3163 } 3148 3164 3149 3165 $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); 3150 } elseif ( $meta && 'video' === $type ) { 3166 } 3167 3168 if ( $meta && 'video' === $type ) { 3151 3169 if ( isset( $meta['width'] ) ) 3152 3170 $response['width'] = (int) $meta['width']; 3153 3171 if ( isset( $meta['height'] ) )