diff --git src/wp-admin/includes/image.php src/wp-admin/includes/image.php
index 84e4c4c..4c33dd5 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 | $sizes = array( |
| 219 | 'thumbnail' => array( |
| 220 | 'width' => get_option( "thumbnail_size_w" ), |
| 221 | 'height' => get_option( "thumbnail_size_h" ), |
| 222 | 'crop' => get_option( "thumbnail_crop" ) |
| 223 | ) |
| 224 | ); |
| 225 | |
| 226 | if ( ! is_wp_error( $editor ) ) { // No support for this type of file |
| 227 | $uploaded = $editor->save( $file . '.jpg' ); |
| 228 | unset( $uploaded['path'] ); |
| 229 | |
| 230 | if ( ! is_wp_error( $uploaded ) ) { |
| 231 | $metadata['sizes'] = $editor->multi_resize( $sizes ); |
| 232 | $metadata['sizes']['full'] = $uploaded; |
| 233 | } |
| 234 | } |
| 235 | } |
204 | 236 | |
205 | 237 | // Remove the blob of binary data from the array. |
206 | 238 | if ( $metadata ) { |
diff --git src/wp-admin/includes/media.php src/wp-admin/includes/media.php
index 1ccb998..e969aea 100644
|
|
function edit_form_image_editor( $post ) { |
2777 | 2777 | */ |
2778 | 2778 | do_action( 'wp_edit_form_attachment_display', $post ); |
2779 | 2779 | |
| 2780 | $image = wp_get_attachment_image( $attachment_id, 'full', false, array( 'style' => 'max-width:100%' ) ); |
| 2781 | if ( $image ) { |
| 2782 | ?> |
| 2783 | |
| 2784 | <div class="wp_attachment_image wp-clearfix" id="media-head-<?php echo $attachment_id; ?>"> |
| 2785 | <p id="thumbnail-head-<?php echo $attachment_id; ?>"> |
| 2786 | <img class="thumbnail" src="<?php echo set_url_scheme( $thumb_url[0] ); ?>" style="max-width:100%" alt="" /> |
| 2787 | </p> |
| 2788 | </div> |
| 2789 | |
| 2790 | <?php |
| 2791 | } |
| 2792 | |
2780 | 2793 | endif; ?> |
2781 | 2794 | </div> |
2782 | 2795 | <div class="wp_attachment_details edit-form-section"> |
diff --git src/wp-includes/class-wp-image-editor-imagick.php src/wp-includes/class-wp-image-editor-imagick.php
index 82b872d..9bc3e41 100644
|
|
class WP_Image_Editor_Imagick extends WP_Image_Editor { |
144 | 144 | wp_raise_memory_limit( 'image' ); |
145 | 145 | |
146 | 146 | try { |
147 | | $this->image = new Imagick( $this->file ); |
| 147 | $this->image = new Imagick(); |
| 148 | |
| 149 | $file_parts = pathinfo( $this->file ); |
| 150 | |
| 151 | // TODO: Allow filtering of filetypes for conditional rendering. |
| 152 | if ( 'pdf' == $file_parts['extension'] ) { |
| 153 | |
| 154 | // TODO: |
| 155 | // Allow filtering of non-image resolutions, given that |
| 156 | // this may break exising code extending WP_Image_Editor for |
| 157 | // non-image types. |
| 158 | $this->image->setResolution( 200, 200 ); |
| 159 | } |
| 160 | |
| 161 | // TODO: This is the first readImage use, and we need to be sure it's available. |
| 162 | $this->image->readImage( $this->file ); |
148 | 163 | |
149 | 164 | if ( ! $this->image->valid() ) |
150 | 165 | 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..3608a0c 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.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 | <# } #> |
diff --git src/wp-includes/media.php src/wp-includes/media.php
index 99adf74..e98aeef 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 | $is_image = wp_attachment_is_image( $id ); |
186 | 187 | |
187 | | if ( !wp_attachment_is_image($id) ) |
| 188 | if ( ! wp_attachment_is_image( $id ) ) { |
188 | 189 | return false; |
| 190 | } |
189 | 191 | |
190 | | /** |
191 | | * Filters whether to preempt the output of image_downsize(). |
192 | | * |
193 | | * Passing a truthy value to the filter will effectively short-circuit |
194 | | * down-sizing the image, returning that value as output instead. |
195 | | * |
196 | | * @since 2.5.0 |
197 | | * |
198 | | * @param bool $downsize Whether to short-circuit the image downsize. Default false. |
199 | | * @param int $id Attachment ID for image. |
200 | | * @param array|string $size Size of image. Image size or array of width and height values (in that order). |
201 | | * Default 'medium'. |
202 | | */ |
203 | | if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) { |
204 | | return $out; |
| 192 | if ( $is_image ) { |
| 193 | /** |
| 194 | * Filters whether to preempt the output of image_downsize(). |
| 195 | * |
| 196 | * Passing a truthy value to the filter will effectively short-circuit |
| 197 | * down-sizing the image, returning that value as output instead. |
| 198 | * |
| 199 | * @since 2.5.0 |
| 200 | * |
| 201 | * @param bool $downsize Whether to short-circuit the image downsize. Default false. |
| 202 | * @param int $id Attachment ID for image. |
| 203 | * @param array|string $size Size of image. Image size or array of width and height values (in that order). |
| 204 | * Default 'medium'. |
| 205 | */ |
| 206 | if ( $out = apply_filters( 'image_downsize', false, $id, $size ) ) { |
| 207 | return $out; |
| 208 | } |
205 | 209 | } |
206 | 210 | |
| 211 | $meta = wp_get_attachment_metadata( $id ); |
| 212 | |
207 | 213 | $img_url = wp_get_attachment_url($id); |
208 | | $meta = wp_get_attachment_metadata($id); |
209 | 214 | $width = $height = 0; |
210 | 215 | $is_intermediate = false; |
211 | 216 | $img_url_basename = wp_basename($img_url); |
212 | 217 | |
| 218 | // If the file isn't an image, attempt to replace its URL with a rendered image from its meta. |
| 219 | if ( ! $is_image && ! empty( $meta['sizes'] ) ) { |
| 220 | $img_url = str_replace( $img_url_basename, $meta['sizes']['full']['file'], $img_url ); |
| 221 | $img_url_basename = $meta['sizes']['full']['file']; |
| 222 | $width = $meta['sizes']['full']['width']; |
| 223 | $height = $meta['sizes']['full']['height']; |
| 224 | } |
| 225 | |
213 | 226 | // try for a new style intermediate size |
214 | 227 | if ( $intermediate = image_get_intermediate_size($id, $size) ) { |
215 | 228 | $img_url = str_replace($img_url_basename, $intermediate['file'], $img_url); |
… |
… |
function image_downsize( $id, $size = 'medium' ) { |
226 | 239 | $is_intermediate = true; |
227 | 240 | } |
228 | 241 | } |
| 242 | |
229 | 243 | if ( !$width && !$height && isset( $meta['width'], $meta['height'] ) ) { |
230 | 244 | // any other type: use the real image |
231 | 245 | $width = $meta['width']; |
… |
… |
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { |
685 | 699 | if ( is_array( $size ) ) { |
686 | 700 | $candidates = array(); |
687 | 701 | |
| 702 | if ( ! isset( $imagedata['file'] ) && isset( $imagedata['sizes']['full'] ) ) { |
| 703 | $imagedata['height'] = $imagedata['sizes']['full']['height']; |
| 704 | $imagedata['width'] = $imagedata['sizes']['full']['width']; |
| 705 | } |
| 706 | |
688 | 707 | foreach ( $imagedata['sizes'] as $_size => $data ) { |
689 | 708 | // If there's an exact match to an existing image size, short circuit. |
690 | 709 | if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) { |
… |
… |
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { |
738 | 757 | } |
739 | 758 | |
740 | 759 | // include the full filesystem path of the intermediate file |
741 | | if ( empty($data['path']) && !empty($data['file']) ) { |
| 760 | if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) { |
742 | 761 | $file_url = wp_get_attachment_url($post_id); |
743 | 762 | $data['path'] = path_join( dirname($imagedata['file']), $data['file'] ); |
744 | 763 | $data['url'] = path_join( dirname($file_url), $data['file'] ); |
… |
… |
function wp_prepare_attachment_for_js( $attachment ) { |
3127 | 3146 | if ( current_user_can( 'delete_post', $attachment->ID ) ) |
3128 | 3147 | $response['nonces']['delete'] = wp_create_nonce( 'delete-post_' . $attachment->ID ); |
3129 | 3148 | |
3130 | | if ( $meta && 'image' === $type ) { |
| 3149 | if ( $meta && ! empty( $meta['sizes'] ) ) { |
3131 | 3150 | $sizes = array(); |
3132 | 3151 | |
3133 | 3152 | /** This filter is documented in wp-admin/includes/media.php */ |
… |
… |
function wp_prepare_attachment_for_js( $attachment ) { |
3175 | 3194 | } |
3176 | 3195 | } |
3177 | 3196 | |
3178 | | $sizes['full'] = array( 'url' => $attachment_url ); |
| 3197 | if ( 'image' === $type ) { |
| 3198 | $sizes['full'] = array( 'url' => $attachment_url ); |
3179 | 3199 | |
3180 | | if ( isset( $meta['height'], $meta['width'] ) ) { |
3181 | | $sizes['full']['height'] = $meta['height']; |
3182 | | $sizes['full']['width'] = $meta['width']; |
3183 | | $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape'; |
| 3200 | if ( isset( $meta['height'], $meta['width'] ) ) { |
| 3201 | $sizes['full']['height'] = $meta['height']; |
| 3202 | $sizes['full']['width'] = $meta['width']; |
| 3203 | $sizes['full']['orientation'] = $meta['height'] > $meta['width'] ? 'portrait' : 'landscape'; |
| 3204 | } |
| 3205 | |
| 3206 | array_merge( $response, $sizes['full'] ); |
| 3207 | } |
| 3208 | else if ( $meta['sizes']['full']['file'] ) { |
| 3209 | $sizes['full'] = array( |
| 3210 | 'url' => $base_url . $meta['sizes']['full']['file'], |
| 3211 | 'height' => $meta['sizes']['full']['height'], |
| 3212 | 'width' => $meta['sizes']['full']['width'], |
| 3213 | 'orientation' => $meta['sizes']['full']['height'] < $meta['sizes']['full']['width'] ? 'portrait' : 'landscape' |
| 3214 | ); |
3184 | 3215 | } |
3185 | 3216 | |
3186 | | $response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] ); |
3187 | | } elseif ( $meta && 'video' === $type ) { |
| 3217 | $response = array_merge( $response, array( 'sizes' => $sizes ) ); |
| 3218 | } |
| 3219 | |
| 3220 | if ( $meta && 'video' === $type ) { |
3188 | 3221 | if ( isset( $meta['width'] ) ) |
3189 | 3222 | $response['width'] = (int) $meta['width']; |
3190 | 3223 | if ( isset( $meta['height'] ) ) |