diff --git src/wp-admin/includes/image.php src/wp-admin/includes/image.php
index aeed988..81a735a 100644
|
|
function wp_generate_attachment_metadata( $attachment_id, $file ) { |
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 | |
| 82 | /** |
| 83 | * Filter attachment mime-types that support thumbnail fallback. |
| 84 | * |
| 85 | * @since 4.5.0 |
| 86 | * |
| 87 | * @param array $mime_types An array of mime-types. |
| 88 | */ |
| 89 | $attachment_fallback_mimetypes = apply_filters( 'attachment_fallback_mimetypes', array( 'application/pdf' ) ); |
| 90 | $mime_type = get_post_mime_type( $attachment ); |
| 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]; |
… |
… |
function wp_generate_attachment_metadata( $attachment_id, $file ) { |
193 | 204 | } |
194 | 205 | } |
195 | 206 | |
| 207 | // Check to see if we support a fallback thumbnail for this mime-type. |
| 208 | else if ( in_array( $mime_type, $attachment_fallback_mimetypes ) && wp_image_editor_supports( array( 'mime_type' => $mime_type ) ) ) { |
| 209 | |
| 210 | $editor = wp_get_image_editor( $file ); |
| 211 | |
| 212 | if ( ! is_wp_error( $editor ) ) { |
| 213 | $uploaded = $editor->save( $file . '.jpg' ); |
| 214 | |
| 215 | if ( ! is_wp_error( $uploaded ) ) { |
| 216 | $sizes = array( |
| 217 | 'thumbnail' => array( |
| 218 | 'width' => get_option( "thumbnail_size_w" ), |
| 219 | 'height' => get_option( "thumbnail_size_h" ), |
| 220 | 'crop' => get_option( "thumbnail_crop" ), |
| 221 | ), |
| 222 | ); |
| 223 | |
| 224 | $metadata['width'] = $uploaded['width']; |
| 225 | $metadata['height'] = $uploaded['height']; |
| 226 | $metadata['file'] = _wp_relative_upload_path( dirname( $file ) . '/' . $uploaded['file'] ); |
| 227 | $metadata['sizes'] = $editor->multi_resize( $sizes ); |
| 228 | } |
| 229 | } |
| 230 | } |
| 231 | |
196 | 232 | // Remove the blob of binary data from the array. |
197 | 233 | if ( $metadata ) { |
198 | 234 | unset( $metadata['image']['data'] ); |
diff --git src/wp-admin/includes/media.php src/wp-admin/includes/media.php
index 966860a..0360ee2 100644
|
|
function edit_form_image_editor( $post ) { |
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"> |
diff --git src/wp-includes/media-template.php src/wp-includes/media-template.php
index 8d7c758..b8fdfd7 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 249e685..2b7d58c 100644
|
|
function image_hwstring( $width, $height ) { |
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; |
| 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 | } |
169 | 186 | |
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; |
| 187 | $meta = wp_get_attachment_metadata($id); |
| 188 | |
| 189 | if ( ! $meta || empty( $meta['sizes'] ) ) { |
| 190 | return false; |
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); |
… |
… |
function image_downsize( $id, $size = 'medium' ) { |
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']; |
… |
… |
function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attac |
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 | |
… |
… |
function wp_prepare_attachment_for_js( $attachment ) { |
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 */ |
… |
… |
function wp_prepare_attachment_for_js( $attachment ) { |
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']; |
… |
… |
function wp_prepare_attachment_for_js( $attachment ) { |
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'] ) ) |