mirror of
https://github.com/WordPress/WordPress.git
synced 2024-09-29 15:47:38 +02:00
Media: Make PDF preview sizes filterable.
This adds a new filter, `fallback_intermediate_image_sizes`, which can be used to modify the array of image sizes created for previewing PDFs in the media library and checks for the existence of sizes before processing any image representations of a PDF. Fixes #38594. Built from https://develop.svn.wordpress.org/trunk@39246 git-svn-id: http://core.svn.wordpress.org/trunk@39186 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
65fb74561b
commit
36ac7287b0
@ -205,26 +205,37 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
|
|||||||
}
|
}
|
||||||
// Try to create image thumbnails for PDFs
|
// Try to create image thumbnails for PDFs
|
||||||
else if ( 'application/pdf' === $mime_type ) {
|
else if ( 'application/pdf' === $mime_type ) {
|
||||||
$editor = wp_get_image_editor( $file );
|
|
||||||
|
|
||||||
$fallback_sizes = array(
|
$fallback_sizes = array(
|
||||||
'thumbnail',
|
'thumbnail',
|
||||||
'medium',
|
'medium',
|
||||||
'large',
|
'large',
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Filters the image sizes generated for non-image mime types.
|
||||||
|
*
|
||||||
|
* @since 4.7.0
|
||||||
|
*
|
||||||
|
* @param array $fallback_sizes An array of image size names.
|
||||||
|
*/
|
||||||
|
$fallback_sizes = apply_filters( 'fallback_intermediate_image_sizes', $fallback_sizes, $metadata );
|
||||||
|
|
||||||
$sizes = array();
|
$sizes = array();
|
||||||
|
|
||||||
foreach ( $fallback_sizes as $s ) {
|
foreach ( $fallback_sizes as $s ) {
|
||||||
$sizes[$s]['width'] = get_option( "{$s}_size_w" );
|
$sizes[ $s ]['width'] = get_option( "{$s}_size_w" );
|
||||||
$sizes[$s]['height'] = get_option( "{$s}_size_h" );
|
$sizes[ $s ]['height'] = get_option( "{$s}_size_h" );
|
||||||
|
|
||||||
// Force thumbnails to be soft crops.
|
// Force thumbnails to be soft crops.
|
||||||
if ( ! 'thumbnail' === $s ) {
|
if ( ! 'thumbnail' === $s ) {
|
||||||
$sizes[$s]['crop'] = get_option( "{$s}_crop" );
|
$sizes[ $s ]['crop'] = get_option( "{$s}_crop" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only load PDFs in an image editor if we're processing sizes.
|
||||||
|
if ( ! empty( $sizes ) ) {
|
||||||
|
$editor = wp_get_image_editor( $file );
|
||||||
|
|
||||||
if ( ! is_wp_error( $editor ) ) { // No support for this type of file
|
if ( ! is_wp_error( $editor ) ) { // No support for this type of file
|
||||||
$uploaded = $editor->save( $file, 'image/jpeg' );
|
$uploaded = $editor->save( $file, 'image/jpeg' );
|
||||||
unset( $editor );
|
unset( $editor );
|
||||||
@ -241,6 +252,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Remove the blob of binary data from the array.
|
// Remove the blob of binary data from the array.
|
||||||
if ( $metadata ) {
|
if ( $metadata ) {
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
*
|
*
|
||||||
* @global string $wp_version
|
* @global string $wp_version
|
||||||
*/
|
*/
|
||||||
$wp_version = '4.7-beta3-39245';
|
$wp_version = '4.7-beta3-39246';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||||
|
Loading…
Reference in New Issue
Block a user