diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 222d35d015..c21c520ada 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -277,6 +277,7 @@ function wp_read_image_metadata( $file ) { 'shutter_speed' => 0, 'title' => '', 'orientation' => 0, + 'keywords' => array(), ); /* @@ -325,6 +326,10 @@ function wp_read_image_metadata( $file ) { if ( ! empty( $iptc['2#116'][0] ) ) // copyright $meta['copyright'] = trim( $iptc['2#116'][0] ); + + if ( ! empty( $iptc['2#025'][0] ) ) { // keywords array + $meta['keywords'] = array_values( $iptc['2#025'] ); + } } } @@ -410,12 +415,14 @@ function wp_read_image_metadata( $file ) { * Filter the array of meta data read from an image's exif data. * * @since 2.5.0 + * @since 4.4.0 The `$iptc` parameter was added. * * @param array $meta Image meta data. * @param string $file Path to image file. * @param int $sourceImageType Type of image. + * @param array $iptc IPTC data. */ - return apply_filters( 'wp_read_image_metadata', $meta, $file, $sourceImageType ); + return apply_filters( 'wp_read_image_metadata', $meta, $file, $sourceImageType, $iptc ); } diff --git a/tests/phpunit/tests/image/meta.php b/tests/phpunit/tests/image/meta.php index 0738f55b9a..30613d48a8 100644 --- a/tests/phpunit/tests/image/meta.php +++ b/tests/phpunit/tests/image/meta.php @@ -138,4 +138,26 @@ class Tests_Image_Meta extends WP_UnitTestCase { $out = wp_read_image_metadata(DIR_TESTDATA.'/images/404_image.png'); $this->assertFalse($out); } + + + /** + * @ticket 33772 + */ + public function test_exif_keywords() { + $out = wp_read_image_metadata(DIR_TESTDATA.'/images/33772.jpg'); + + $this->assertEquals( '8', $out['aperture'] ); + $this->assertEquals( 'Photoshop Author', $out['credit'] ); + $this->assertEquals( 'DMC-LX2', $out['camera'] ); + $this->assertEquals( 'Photoshop Description', $out['caption'] ); + $this->assertEquals( 1306315327, $out['created_timestamp'] ); + $this->assertEquals( 'Photoshop Copyrright Notice', $out['copyright'] ); + $this->assertEquals( '6.3', $out['focal_length'] ); + $this->assertEquals( '100', $out['iso'] ); + $this->assertEquals( '0.0025', $out['shutter_speed'] ); + $this->assertEquals( 'Photoshop Document Ttitle', $out['title'] ); + $this->assertEquals( 1, $out['orientation']); + $this->assertEquals( array( 'beach', 'baywatch', 'LA', 'sunset' ), $out['keywords'] ); + } + }