Media: Recognize `.ico` files as displayable images on PHP 5.3+ and allow attachment meta data to be generated for them.

Props remyvv, Guido07111975.
Fixes #43458.

git-svn-id: https://develop.svn.wordpress.org/trunk@42780 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov 2018-03-05 01:02:20 +00:00
parent 9de76899c1
commit 007a7caad4
3 changed files with 15 additions and 0 deletions

View File

@ -556,6 +556,11 @@ function file_is_valid_image( $path ) {
function file_is_displayable_image( $path ) {
$displayable_image_types = array( IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG, IMAGETYPE_BMP );
// IMAGETYPE_ICO is only defined in PHP 5.3+.
if ( defined( 'IMAGETYPE_ICO' ) ) {
$displayable_image_types[] = IMAGETYPE_ICO;
}
$info = @getimagesize( $path );
if ( empty( $info ) ) {
$result = false;

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

View File

@ -61,6 +61,11 @@ class Tests_Image_Functions extends WP_UnitTestCase {
'test-image.jpg',
);
// IMAGETYPE_ICO is only defined in PHP 5.3+.
if ( defined( 'IMAGETYPE_ICO' ) ) {
$files[] = 'test-image.ico';
}
foreach ( $files as $file ) {
$this->assertTrue( file_is_valid_image( DIR_TESTDATA . '/images/' . $file ), "file_is_valid_image($file) should return true" );
}
@ -87,6 +92,11 @@ class Tests_Image_Functions extends WP_UnitTestCase {
'test-image.jpg',
);
// IMAGETYPE_ICO is only defined in PHP 5.3+.
if ( defined( 'IMAGETYPE_ICO' ) ) {
$files[] = 'test-image.ico';
}
foreach ( $files as $file ) {
$this->assertTrue( file_is_displayable_image( DIR_TESTDATA . '/images/' . $file ), "file_is_valid_image($file) should return true" );
}