diff --git src/wp-admin/includes/image.php src/wp-admin/includes/image.php
index 84e4c4c..6058197 100644
|
|
|
function wp_generate_attachment_metadata( $attachment_id, $file ) { |
| 76 | 76 | |
| 77 | 77 | $metadata = array(); |
| 78 | 78 | $support = false; |
| 79 | | if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) { |
| | 79 | $mime_type = get_post_mime_type( $attachment ); |
| | 80 | |
| | 81 | /** |
| | 82 | * Filter attachment mime-types that support thumbnail fallback. |
| | 83 | * |
| | 84 | * @since 4.7.0 |
| | 85 | * |
| | 86 | * @param array $mime_types An array of mime-types. |
| | 87 | */ |
| | 88 | $attachment_fallback_mimetypes = apply_filters( 'attachment_fallback_mimetypes', array( 'application/pdf' ) ); |
| | 89 | |
| | 90 | if ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image( $file ) ) { |
| 80 | 91 | $imagesize = getimagesize( $file ); |
| 81 | 92 | $metadata['width'] = $imagesize[0]; |
| 82 | 93 | $metadata['height'] = $imagesize[1]; |
| … |
… |
function wp_generate_attachment_metadata( $attachment_id, $file ) { |
| 201 | 212 | } |
| 202 | 213 | } |
| 203 | 214 | } |
| | 215 | // Check to see if we support a fallback thumbnail for this mime-type. |
| | 216 | else if ( in_array( $mime_type, $attachment_fallback_mimetypes ) ) { |
| | 217 | $editor = wp_get_image_editor( $file ); |
| | 218 | |
| | 219 | $fallback_sizes = array( |
| | 220 | 'thumbnail', |
| | 221 | 'medium', |
| | 222 | 'large', |
| | 223 | ); |
| | 224 | |
| | 225 | $sizes = array(); |
| | 226 | |
| | 227 | foreach ( $fallback_sizes as $s ) { |
| | 228 | $sizes[$s]['width'] = get_option( "{$s}_size_w" ); |
| | 229 | $sizes[$s]['height'] = get_option( "{$s}_size_h" ); |
| | 230 | $sizes[$s]['crop'] = get_option( "{$s}_crop" ); |
| | 231 | } |
| | 232 | |
| | 233 | if ( ! is_wp_error( $editor ) ) { // No support for this type of file |
| | 234 | $uploaded = $editor->save( $file, 'image/jpeg' ); |
| | 235 | unset( $editor ); |
| | 236 | |
| | 237 | // Resize based on the full size image, rather than the source. |
| | 238 | if ( ! is_wp_error( $uploaded ) ) { |
| | 239 | $editor = wp_get_image_editor( $uploaded['path'] ); |
| | 240 | unset( $uploaded['path'] ); |
| | 241 | |
| | 242 | if ( ! is_wp_error( $editor ) ) { |
| | 243 | $metadata['sizes'] = $editor->multi_resize( $sizes ); |
| | 244 | $metadata['sizes']['full'] = $uploaded; |
| | 245 | } |
| | 246 | } |
| | 247 | } |
| | 248 | } |
| 204 | 249 | |
| 205 | 250 | // Remove the blob of binary data from the array. |
| 206 | 251 | if ( $metadata ) { |
diff --git src/wp-admin/includes/media.php src/wp-admin/includes/media.php
index 1ccb998..c79e312 100644
|
|
|
function edit_form_image_editor( $post ) { |
| 2766 | 2766 | |
| 2767 | 2767 | echo wp_video_shortcode( $attr ); |
| 2768 | 2768 | |
| 2769 | | else : |
| | 2769 | elseif ( isset( $thumb_url[0] ) ): |
| | 2770 | |
| | 2771 | ?> |
| | 2772 | <div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
| | 2773 | <p id="thumbnail-head-<?php echo $attachment_id; ?>"> |
| | 2774 | <img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /> |
| | 2775 | </p> |
| | 2776 | </div> |
| | 2777 | <?php |
| | 2778 | |
| | 2779 | else: |
| 2770 | 2780 | |
| 2771 | 2781 | /** |
| 2772 | 2782 | * Fires when an attachment type can't be rendered in the edit form. |
diff --git src/wp-includes/class-wp-image-editor-imagick.php src/wp-includes/class-wp-image-editor-imagick.php
index 82b872d..fb56eb1 100644
|
|
|
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 73 | 73 | 'rotateimage', |
| 74 | 74 | 'flipimage', |
| 75 | 75 | 'flopimage', |
| | 76 | 'readimage', |
| 76 | 77 | ); |
| 77 | 78 | |
| 78 | 79 | // Now, test for deep requirements within Imagick. |
| … |
… |
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
| 144 | 145 | wp_raise_memory_limit( 'image' ); |
| 145 | 146 | |
| 146 | 147 | try { |
| 147 | | $this->image = new Imagick( $this->file ); |
| | 148 | $this->image = new Imagick(); |
| | 149 | $file_parts = pathinfo( $this->file ); |
| | 150 | |
| | 151 | // By default, PDFs are rendered in a very low resolution. |
| | 152 | // We want the thumbnail to be readable, so increase the rendering dpi. |
| | 153 | if ( 'pdf' == strtolower( $file_parts['extension'] ) ) { |
| | 154 | $this->image->setResolution( 128, 128 ); |
| | 155 | } |
| | 156 | |
| | 157 | // Reading image after Imagick instantiation because `setResolution` |
| | 158 | // only applies correctly before the image is read. |
| | 159 | $this->image->readImage( $this->file ); |
| 148 | 160 | |
| 149 | 161 | if ( ! $this->image->valid() ) |
| 150 | 162 | return new WP_Error( 'invalid_image', __('File is not an image.'), $this->file); |
diff --git src/wp-includes/media-template.php src/wp-includes/media-template.php
index c669921..95fbb9a 100644
|
|
|
function wp_print_media_templates() { |
| 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="" /> |
| … |
… |
function wp_print_media_templates() { |
| 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.medium ) { #> |
| | 458 | <img src="{{ data.sizes.medium.url }}" class="thumbnail" draggable="false" alt="" /> |
| 457 | 459 | <# } else { #> |
| 458 | 460 | <img src="{{ data.icon }}" class="icon" draggable="false" alt="" /> |
| 459 | 461 | <# } #> |
diff --git src/wp-includes/media.php src/wp-includes/media.php
index f6c5f0f..ad73301 100644
|
|
|
function image_hwstring( $width, $height ) { |
| 183 | 183 | * the image is an intermediate size. False on failure. |
| 184 | 184 | */ |
| 185 | 185 | function image_downsize( $id, $size = 'medium' ) { |
| 186 | | |
| 187 | | if ( !wp_attachment_is_image($id) ) |
| 188 | | return false; |
| | 186 | $is_image = wp_attachment_is_image( $id ); |
| 189 | 187 | |
| 190 | 188 | /** |
| 191 | 189 | * Filters whether to preempt the output of image_downsize(). |
| … |
… |
function image_downsize( $id, $size = 'medium' ) { |
| 210 | 208 | $is_intermediate = false; |
| 211 | 209 | $img_url_basename = wp_basename($img_url); |
| 212 | 210 | |
| | 211 | // If the file isn't an image, attempt to replace its URL with a rendered image from its meta. |
| | 212 | // Otherwise, a non-image type could be returned. |
| | 213 | if ( ! $is_image ) { |
| | 214 | if ( ! empty( $meta['sizes'] ) ) { |
| | 215 | $img_url = str_replace( $img_url_basename, $meta['sizes']['full']['file'], $img_url ); |
| | 216 | $img_url_basename = $meta['sizes']['full']['file']; |
| | 217 | $width = $meta['sizes']['full']['width']; |
| | 218 | $height = $meta['sizes']['full']['height']; |
| | 219 | } else { |
| | 220 | return false; |
| | 221 | } |
| | 222 | } |
| | 223 | |
| 213 | 224 | // try for a new style intermediate size |
| 214 | 225 | if ( $intermediate = image_get_intermediate_size($id, $size) ) { |
| 215 | 226 | $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url); |
| … |
… |
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { |
| 685 | 696 | if ( is_array( $size ) ) { |
| 686 | 697 | $candidates = array(); |
| 687 | 698 | |
| | 699 | if ( ! isset( $imagedata['file'] ) && isset( $imagedata['sizes']['full'] ) ) { |
| | 700 | $imagedata['height'] = $imagedata['sizes']['full']['height']; |
| | 701 | $imagedata['width'] = $imagedata['sizes']['full']['width']; |
| | 702 | } |
| | 703 | |
| 688 | 704 | foreach ( $imagedata['sizes'] as $_size => $data ) { |
| 689 | 705 | // If there's an exact match to an existing image size, short circuit. |
| 690 | 706 | if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) { |
| … |
… |
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { |
| 738 | 754 | } |
| 739 | 755 | |
| 740 | 756 | // include the full filesystem path of the intermediate file |
| 741 | | if ( empty($data['path']) && !empty($data['file']) ) { |
| | 757 | if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) { |
| 742 | 758 | $file_url = wp_get_attachment_url($post_id); |
| 743 | 759 | $data['path'] = path_join( dirname($imagedata['file']), $data['file'] ); |
| 744 | 760 | $data['url'] = path_join( dirname($file_url), $data['file'] ); |
| … |
… |
function wp_prepare_attachment_for_js( $attachment ) { |
| 3123 | 3139 | if ( current_user_can( 'delete_post', $attachment->ID ) ) |
| 3124 | 3140 | $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); |
| 3125 | 3141 | |
| 3126 | | if ( $meta && 'image' === $type ) { |
| | 3142 | if ( $meta && ! empty( $meta['sizes'] ) ) { |
| 3127 | 3143 | $sizes = array(); |
| 3128 | 3144 | |
| 3129 | 3145 | /** This filter is documented in wp-admin/includes/media.php */ |
| … |
… |
function wp_prepare_attachment_for_js( $attachment ) { |
| 3171 | 3187 | } |
| 3172 | 3188 | } |
| 3173 | 3189 | |
| 3174 | | $sizes['full'] = array( 'url' => $attachment_url ); |
| | 3190 | if ( 'image' === $type ) { |
| | 3191 | $sizes['full'] = array( 'url' => $attachment_url ); |
| | 3192 | |
| | 3193 | if ( isset( $meta['height'], $meta['width'] ) ) { |
| | 3194 | $sizes['full']['height'] = $meta['height']; |
| | 3195 | $sizes['full']['width'] = $meta['width']; |
| | 3196 | $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape'; |
| | 3197 | } |
| 3175 | 3198 | |
| 3176 | | if ( isset( $meta['height'], $meta['width'] ) ) { |
| 3177 | | $sizes['full']['height'] = $meta['height']; |
| 3178 | | $sizes['full']['width'] = $meta['width']; |
| 3179 | | $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape'; |
| | 3199 | $response = array_merge( $response, $sizes['full'] ); |
| | 3200 | } elseif ( $meta['sizes']['full']['file'] ) { |
| | 3201 | $sizes['full'] = array( |
| | 3202 | 'url' => $base_url . $meta['sizes']['full']['file'], |
| | 3203 | 'height' => $meta['sizes']['full']['height'], |
| | 3204 | 'width' => $meta['sizes']['full']['width'], |
| | 3205 | 'orientation' => $meta['sizes']['full']['height'] > $meta['sizes']['full']['width'] ? 'portrait' : 'landscape' |
| | 3206 | ); |
| 3180 | 3207 | } |
| 3181 | 3208 | |
| 3182 | | $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); |
| 3183 | | } elseif ( $meta && 'video' === $type ) { |
| | 3209 | $response = array_merge( $response, array( 'sizes' => $sizes ) ); |
| | 3210 | } |
| | 3211 | |
| | 3212 | if ( $meta && 'video' === $type ) { |
| 3184 | 3213 | if ( isset( $meta['width'] ) ) |
| 3185 | 3214 | $response['width'] = (int) $meta['width']; |
| 3186 | 3215 | if ( isset( $meta['height'] ) ) |