Index: src/wp-admin/includes/image.php
===================================================================
--- src/wp-admin/includes/image.php (revision 36486)
+++ src/wp-admin/includes/image.php (working copy)
@@ -78,7 +78,10 @@
$metadata = array();
$support = false;
- if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) {
+ $attachment_fallback_mimetypes = apply_filters( 'attachment_fallback_mimetypes', array( 'application/pdf', 'video/avi' ) );
+ $mime_type = get_post_mime_type( $attachment );
+
+ if ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image($file) ) {
$imagesize = getimagesize( $file );
$metadata['width'] = $imagesize[0];
$metadata['height'] = $imagesize[1];
@@ -192,7 +195,23 @@
}
}
}
+ else if ( in_array( $mime_type, $attachment_fallback_mimetypes ) ) {
+ $editor = wp_get_image_editor( $file );
+ if ( ! is_wp_error( $editor ) ) { // No support for this type of file
+ $uploaded = $editor->save( $file . '.jpg' );
+
+ if ( ! is_wp_error( $uploaded ) ) {
+ unset( $uploaded['path'] );
+
+ $metadata = array_merge( $metadata, $uploaded );
+ $metadata['sizes'] = array(
+ 'full' => $uploaded
+ );
+ }
+ }
+ }
+
// Remove the blob of binary data from the array.
if ( $metadata ) {
unset( $metadata['image']['data'] );
Index: src/wp-includes/media-template.php
===================================================================
--- src/wp-includes/media-template.php (revision 36486)
+++ src/wp-includes/media-template.php (working copy)
@@ -290,9 +290,9 @@
<# if ( data.uploading ) { #>
- <# } else if ( 'image' === data.type && data.sizes && data.sizes.large ) { #>
+ <# } else if ( data.sizes && data.sizes.large ) { #>
- <# } else if ( 'image' === data.type && data.sizes && data.sizes.full ) { #>
+ <# } else if ( data.sizes && data.sizes.full ) { #>
<# } else if ( -1 === jQuery.inArray( data.type, [ 'audio', 'video' ] ) ) { #>
@@ -450,6 +450,10 @@
+ <# } else if ( data.sizes ) { #>
+
+
+
<# } else { #>
<# if ( data.image && data.image.src && data.image.src !== data.icon ) { #>
Index: src/wp-includes/media.php
===================================================================
--- src/wp-includes/media.php (revision 36486)
+++ src/wp-includes/media.php (working copy)
@@ -1006,7 +1006,7 @@
*/
$image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id );
- if ( empty( $image_meta['sizes'] ) ) {
+ if ( empty( $image_meta['file'] ) || empty( $image_meta['sizes'] ) ) {
return false;
}
@@ -3147,7 +3147,21 @@
}
$response = array_merge( $response, array( 'sizes' => $sizes ), $sizes['full'] );
- } elseif ( $meta && 'video' === $type ) {
+ }
+ elseif ( isset( $meta['sizes'] ) ) {
+ $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url );
+
+ foreach ( $meta['sizes'] as $size => $data ) {
+ $response['sizes'][ $size ] = array(
+ 'height' => $data['height'],
+ 'width' => $data['width'],
+ 'url' => $base_url . $data['file'],
+ 'orientation' => $data['height'] > $data['width'] ? 'portrait' : 'landscape',
+ );
+ }
+ }
+
+ if ( $meta && 'video' === $type ) {
if ( isset( $meta['width'] ) )
$response['width'] = (int) $meta['width'];
if ( isset( $meta['height'] ) )