Ticket #31050: 31050.6.patch
File 31050.6.patch, 9.1 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 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, $meta['sizes']['full']['file'], $img_url ); 200 $img_url_basename = $meta['sizes']['full']['file']; 201 $width = $meta['sizes']['full']['width']; 202 $height = $meta['sizes']['full']['height']; 203 } 204 193 205 // try for a new style intermediate size 194 206 if ( $intermediate = image_get_intermediate_size($id, $size) ) { 195 207 $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url); … … 206 218 $is_intermediate = true; 207 219 } 208 220 } 221 209 222 if ( !$width && !$height && isset( $meta['width'], $meta['height'] ) ) { 210 223 // any other type: use the real image 211 224 $width = $meta['width']; … … 637 650 if ( is_array($size) && !empty($imagedata['sizes']) ) { 638 651 $candidates = array(); 639 652 653 if ( ! isset( $imagedata['file'] ) && isset( $imagedata['sizes']['full'] ) ) { 654 $imagedata['height'] = $imagedata['sizes']['full']['height']; 655 $imagedata['width'] = $imagedata['sizes']['full']['width']; 656 } 657 640 658 foreach ( $imagedata['sizes'] as $_size => $data ) { 641 659 // If there's an exact match to an existing image size, short circuit. 642 660 if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) { … … 682 700 683 701 $data = $imagedata['sizes'][$size]; 684 702 // include the full filesystem path of the intermediate file 685 if ( empty($data['path']) && ! empty($data['file']) ) {703 if ( empty($data['path']) && ! empty($data['file']) && ! empty($imagedata['file'] ) ) { 686 704 $file_url = wp_get_attachment_url($post_id); 687 705 $data['path'] = path_join( dirname($imagedata['file']), $data['file'] ); 688 706 $data['url'] = path_join( dirname($file_url), $data['file'] ); … … 985 1003 */ 986 1004 $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id ); 987 1005 988 if ( empty( $image_meta[' sizes'] ) ) {1006 if ( empty( $image_meta['file'] ) || empty( $image_meta['sizes'] ) ) { 989 1007 return false; 990 1008 } 991 1009 … … 3069 3087 if ( current_user_can( 'delete_post', $attachment->ID ) ) 3070 3088 $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); 3071 3089 3072 if ( $meta && 'image' === $type) {3090 if ( $meta && ! empty($meta['sizes']) ) { 3073 3091 $sizes = array(); 3074 3092 3075 3093 /** This filter is documented in wp-admin/includes/media.php */ … … 3117 3135 } 3118 3136 } 3119 3137 3120 $sizes['full'] = array( 'url' => $attachment_url ); 3138 if ( 'image' === $type ) { 3139 $sizes['full'] = array( 'url' => $attachment_url ); 3140 } 3141 else if( $meta['sizes']['full']['file'] ) { 3142 $sizes['full'] = array( 3143 'url' => $base_url . $meta['sizes']['full']['file'], 3144 'height' => $meta['sizes']['full']['height'], 3145 'width' => $meta['sizes']['full']['width'], 3146 'orientation' => $meta['sizes']['full']['height'] < $meta['sizes']['full']['width'] ? 'portrait' : 'landscape' 3147 ); 3148 } 3121 3149 3122 3150 if ( isset( $meta['height'], $meta['width'] ) ) { 3123 3151 $sizes['full']['height'] = $meta['height']; … … 3126 3154 } 3127 3155 3128 3156 $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); 3129 } elseif ( $meta && 'video' === $type ) { 3157 } 3158 3159 if ( $meta && 'video' === $type ) { 3130 3160 if ( isset( $meta['width'] ) ) 3131 3161 $response['width'] = (int) $meta['width']; 3132 3162 if ( isset( $meta['height'] ) )