Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#33772 closed enhancement (fixed)

Include IPTC Keywords in image_metadata array

Reported by: stevehoneynz's profile SteveHoneyNZ Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.4
Component: Media Keywords: has-patch
Focuses: Cc:


IPTC data is already parsed in the attachment metadata process, and use of IPTC keywords is often requested, and there are a number of plugin solutions for using keywords and other IPTC meta.

In core currently the comments around IPTC note that it's selecting only values considered to be "useful" and consistently avaialable. As Adobe and others have almost universally adopted IPTC tag 2#025 as containing keywords it would be useful for developers to have access to these in the image_meta array of attachment_metadata.

The attached demonstrates a small addition to the wp_read_image_metadata function which adds the keywords as a non-indexed array.

Possible negatives - the array values should potentially be escaped/sanitized (I'm unsure what the iptc parse function already does in this respect). Also as attachment_metadata is one serialized db entry images with exceptionally large amonuts of keywords added may become bloated, possibly limit to say 99 by trimming array.

As an example use case I was working on a plugin that bulk creates WooCommerce products from images for print/digital sales, I wanted to add the keywords as product tags for search purposes. With this addition I was able to accomplish that.

Attachments (5)

add-iptc-keywords-to-attachment-metadata.php (6.2 KB) - added by SteveHoneyNZ 9 years ago.
33772.patch (906 bytes) - added by SteveHoneyNZ 9 years ago.
image-with-iptc-keywords-test-patch-33772.jpg (172.5 KB) - added by SteveHoneyNZ 9 years ago.
Image with IPTC Keywords and other Adobe meta set
33772.diff (2.8 KB) - added by dbru 9 years ago.
33772.2.diff (2.6 KB) - added by swissspidy 9 years ago.

Download all attachments as: .zip

Change History (19)

#1 @SteveHoneyNZ
9 years ago

Also proposing passing the available $iptc array to wp_read_image_metadata filter fired at end of function to allow developers to access any available IPTC tag data and return it the meta array as they wish. Can't see any negative impact of this, and if adding keywords by default isn't thought a good idea as a default, then just including the iptc array in the filter would mean I could still accomplish the same functionality via the filter.

#2 @swissspidy
9 years ago

#33771 was marked as a duplicate.

#3 @swissspidy
9 years ago

  • Keywords needs-patch added

Hey there, thanks for your report and welcome to trac!

Could you please update a real patch showing the differences between the original file and your changes? You can read more about working with patches here:

#4 @swissspidy
9 years ago

  • Keywords needs-unit-tests added

9 years ago

#5 @SteveHoneyNZ
9 years ago

  • Keywords has-patch added; needs-patch removed

#6 @wonderboymusic
9 years ago

  • Keywords reporter-feedback added
  • Milestone changed from Awaiting Review to Future Release

@SteveHoneyNZ - can you upload an image to the ticket that has that IPTC data for testing?

9 years ago

Image with IPTC Keywords and other Adobe meta set

#7 @SteveHoneyNZ
9 years ago

The image above should return the following image_meta array from wp_get_attachment_metadata if patch is working as intended:

    [image_meta] => Array
            [aperture] => 8
            [credit] => Photoshop Author
            [camera] => DMC-LX2
            [caption] => Photoshop Description
            [created_timestamp] => 1306315327
            [copyright] => Photoshop Copyrright Notice
            [focal_length] => 6.3
            [iso] => 100
            [shutter_speed] => 0.0025
            [title] => Photoshop Document Ttitle
            [orientation] => 1
            [keywords] => Array
                    [0] => beach
                    [1] => baywatch
                    [2] => LA
                    [3] => sunset

Last edited 9 years ago by SteveHoneyNZ (previous) (diff)

#8 @swissspidy
9 years ago

  • Keywords reporter-feedback removed

Cool. I'm gonna write a test for that.

9 years ago

#9 @swissspidy
9 years ago

  • Keywords needs-unit-tests removed
  • Milestone changed from Future Release to 4.4

9 years ago

#10 @wonderboymusic
9 years ago

  • Owner set to wonderboymusic
  • Resolution set to fixed
  • Status changed from new to closed

In 34374:

Media: In wp_read_image_metadata(), include IPTC Keywords when available in $meta.

Adds unit test.

Props swissspidy, dbru, SteveHoneyNZ.
Fixes #33772.

#11 @wonderboymusic
9 years ago

In 34378:

After [34374], ensure that $iptc is defined.

See #33772.

This ticket was mentioned in Slack in #core by swissspidy. View the logs.

9 years ago

#13 @jorbin
9 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Unit test introduced here is broken due to missing test image.

#14 @jorbin
9 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 34448:

Add test image for test_exif_keywords test

[34374] added a test that relies on a new test image. This test image wasn't included in the commit. This fixes the broken Tests_Image_Meta::test_exif_keywords test.

Props swissspidy, SteveHoneyNZ.
Fixes #33772.

Note: See TracTickets for help on using tickets.