Make WordPress Core

Opened 21 months ago

Closed 11 months ago

Last modified 11 months ago

#58082 closed defect (bug) (fixed)

Import metadata description from Darktable into media caption in WordPress

Reported by: fotodrachen's profile fotodrachen Owned by: joedolson's profile joedolson
Milestone: 6.5 Priority: normal
Severity: normal Version: 6.2
Component: Media Keywords: has-patch commit
Focuses: Cc:

Description (last modified by sabernhardt)

WordPress 6.2 in interaction with Darktable 4.2.1

It should be possible to set Metadata in the Photo-Editor "Darktable" that can be used as "caption" (and "title") in WordPress without typing it once again.

In Darktable there are 3 metadata-fields in the internal database: title, description, notices.
While exporting from Darktable to JPEG the metadata can be written into the JPG-file. There are 3 groups of metadata: EXIF, IPTC and Xmp.

Darktable writes EXIF and Xmp.
WordPress reads EXIF and IPTC.
So only EXIF can be used.

Darktable writes only the "description" into the EXIF-group, the fields "title" and "notices" only in Xmp.
So only the Darktable-field "description" can be used for WordPress-caption and title.

If the description has "ASCII only" characters, Darktable exports the description to "EXIF ImageDescription field".
If the description contains some special characters (like in german ä ö ü), then Darktable writes the Description to "EXIF UserComment field".
So "EXIF ImageDescription field" OR "EXIF UserComment field" is filled, but never both.

The "EXIF UserComment field" is not imported to the WordPress-caption when "EXIF ImageDescription field" is empty (wrong if-structure?).

So at least only descriptions with "ASCII only"-characters are imported from darktable, texts with special national characters are lost.

Please enable the import of the "EXIF UserComment field".

Source-code is: function wp_read_image_metadata() in /wp-admin/includes/image.php.
Inserting this 7 lines of code at line 877 solved the problem for me:

<?php
// }
} elseif ( empty( $meta['caption'] ) && ! empty( $exif['COMPUTED']['UserComment'] ) ) {
        $meta['caption'] = trim( $exif['COMPUTED']['UserComment'] );
        $description_length = strlen( $exif['COMPUTED']['UserComment'] );
        if ( empty( $meta['title'] ) && $description_length < 80 ) {
                $meta['title'] = trim( $exif['COMPUTED']['UserComment'] );
        }
}

Documentation in German: https://fotodrachen.de/wp/wordpress-bildunterschrift-aus-darktable-metadaten-auslesen/

On long term it could be useful also to import metadata from the Xmp-group, for example to get different description and title.

Attachments (9)

58082.diff (793 bytes) - added by mikinc860 18 months ago.
Uploaded the diff based on provided code.
example_with_umlaut.jpg (311.5 KB) - added by fotodrachen 14 months ago.
Example Picture, edited in DarkTable, Metadata with special Characters
example_without_umlaut.jpg (280.6 KB) - added by fotodrachen 14 months ago.
Example Picture, edited in DarkTable, Metadata with ACSII-only characters
before-patch-with-umlaut-no-caption.png (1.3 MB) - added by joedolson 14 months ago.
Before patch; has umlaut, no caption,.
before-patch-no-umlaut-has-caption.png (1.3 MB) - added by joedolson 14 months ago.
Before patch, no umlaust, has caption.
after-patch-has-umlaut-has-caption.png (1.3 MB) - added by joedolson 14 months ago.
After patch, has umlaut, has caption
without_patch_58082.png (1.4 MB) - added by antpb 11 months ago.
without patch
with_patch_without_umlaut_58082.png (1.3 MB) - added by antpb 11 months ago.
with patch without umlaut
with_patch_with_umlaut_58082.png (1.4 MB) - added by antpb 11 months ago.
with patch with umlaut

Change History (41)

#1 @sabernhardt
21 months ago

  • Component changed from Administration to Media
  • Description modified (diff)
  • Summary changed from Import metadata description from darktable into media caption in wordpress to Import metadata description from Darktable into media caption in WordPress

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


21 months ago

#3 @antpb
21 months ago

  • Milestone changed from Awaiting Review to 6.3

Hello @fotodrachen ! We reviewed this ticket in the recent Core Media meeting and think there is some improvement that could be made Core side to make this a better experience. Standards suggest UserComment as the intended substitute for ImageDescription when multibyte characters are needed. One way forward might be to append the UserComment if defined to ImageDescription.

And for future reference, here's the exif standard: https://www.kodak.com/global/plugins/acrobat/en/service/digCam/exifStandard2.pdf

This ticket was mentioned in Slack in #core-media by joedolson. View the logs.


19 months ago

#5 @joedolson
19 months ago

  • Owner set to joedolson
  • Status changed from new to accepted

#6 @joedolson
19 months ago

Our proposal is:

If identical, use ImageDescription; if one field is empty, use the one that's populated, if both populated, append in order ImageDescription + UserComment; add filter so plugins can adjust this behavior.

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


18 months ago

@mikinc860
18 months ago

Uploaded the diff based on provided code.

#8 @mikinc860
18 months ago

  • Keywords has-patch added

#9 @oglekler
18 months ago

  • Keywords needs-testing added

#10 @azaozz
17 months ago

  • Milestone changed from 6.3 to 6.4
  • Type changed from defect (bug) to enhancement

This ticket type is set as "bug" but it sounds more like an enhancement? Also seems it may be too late to add it to 6.3, RC is in few days.

Setting as enhancement and to the 6.4 milestone. Feel free to move it back to 6.3 if somebody is ready to test and fix this now.

#11 follow-up: @joedolson
17 months ago

  • Type changed from enhancement to defect (bug)

I think this should remain a bug; WordPress fails to read the appropriate description data out of the image meta in some circumstances, failing to follow the EXIF spec regarding multibyte characters when reading this data.

#12 in reply to: ↑ 11 @azaozz
17 months ago

Replying to joedolson:

Sure. In this case it seems that the EXIF "UserComment" should have a higher priority than the old, non-standard "Comment". I.e. the patch needs a small update.

#13 @fotodrachen
17 months ago

It's a bug and it's a small update.

The code for import the EXIF "UserComment" is already there. But it is wrapped in a wrong IF-structure (bug!).
A filled "UserComment" is only imported, when "ImageDescription" is also non-empty. This never happens for pics from DarkTable.
"ImageDescription" is filled for only-ascii text from the description-metadata in DarkTable, "UserComment" is filled for NOT-only-ascii text.
So "ImageDescription" OR "UserComment" is filled in the EXIF-data in a picture, but never both.
"UserComment" should be imported even if "ImageDescription" is empty, it's the alternative.

I added this case at the end of the if-else-structure. May be there is a smarter solution modifying a if-condition.

This ticket was mentioned in Slack in #core-media by joedolson. View the logs.


17 months ago

#15 @joedolson
17 months ago

  • Keywords early added

This ticket was mentioned in Slack in #core-media by joedolson. View the logs.


17 months ago

#17 @hellofromTonya
16 months ago

  • Keywords early removed

I've removed the early keyword. Why?

The handbook explains the keyword as:

This keyword should only be applied by committers. The keyword signals that the ticket is a priority, and should be handled early in the next release cycle.

early means the commits need to happen during the early part of the Alpha cycle; else, the ticket gets bumped.

Though it would be great to prepare the work for commit as early as possible, commits for this ticket should not be constrained to only happen during the early Alpha phase. Rather, defect commits can happen up to 6.4 RC 1.

To aid in 6.4 tracking and scrubs, I've removed the early keyword.

#18 @nicolefurlan
15 months ago

It seems that the description for this ticket is sufficient for testing info – although I'm sure some clear, concise testing steps would be appreciated by testing folks if anyone would be willing to add that to the ticket.

Could someone provide example images with metadata to cover all test cases? It seems like that would be needed for testing.

RC1 for 6.4 is ~2 weeks away so it would be great to get this tested ASAP so that it can be included. (cc @fotodrachen)

Thanks :)

This ticket was mentioned in Slack in #core-media by antpb. View the logs.


15 months ago

@fotodrachen
14 months ago

Example Picture, edited in DarkTable, Metadata with special Characters

@fotodrachen
14 months ago

Example Picture, edited in DarkTable, Metadata with ACSII-only characters

#20 @fotodrachen
14 months ago

I added two example-pictures:

$ exiv2  -pa  example_*.jpg | grep WP-Test

example_without_umlaut.jpg  Exif.Image.ImageDescription                  Ascii      32  WP-Test Description ohne Umlaut
example_without_umlaut.jpg  Xmp.acdsee.notes                             XmpText    27  WP-Test Comment ohne Umlaut
example_without_umlaut.jpg  Xmp.dc.title                                 LangAlt     1  lang="x-default" WP-Test Title ohne Umlaut
example_without_umlaut.jpg  Xmp.dc.description                           LangAlt     1  lang="x-default" WP-Test Description ohne Umlaut

example_with_umlaut.jpg  Exif.Photo.UserComment                       Undefined  53  WP-Test Description mit Umlaut ÄÖÜäöüß
example_with_umlaut.jpg  Xmp.acdsee.notes                             XmpText    41  WP-Test Comment mit Umlaut ÄÖÜäöüß
example_with_umlaut.jpg  Xmp.dc.title                                 LangAlt     1  lang="x-default" WP-Test Title mit Umlaut ÄÖÜäöüß
example_with_umlaut.jpg  Xmp.dc.description                           LangAlt     1  lang="x-default" WP-Test Description mit Umlaut ÄÖÜäöüß

This ticket was mentioned in PR #5430 on WordPress/wordpress-develop by @joedolson.


14 months ago
#21

Updates patch 58082.diff & handles case where both ImageDescription and UserComments are added.

Trac ticket: https://core.trac.wordpress.org/ticket/58082

@joedolson
14 months ago

Before patch; has umlaut, no caption,.

@joedolson
14 months ago

Before patch, no umlaust, has caption.

@joedolson
14 months ago

After patch, has umlaut, has caption

This ticket was mentioned in Slack in #core-test by oglekler. View the logs.


14 months ago

#23 @joedolson
14 months ago

PR adds cases and updates tests. Test test_exif_d70_mf() failed because this change causes the 'caption' value to be replaced by user comments when it is available; previously that image would have had an empty caption. It also results in the previously empty 'title' field being filled by the user comments field.

#24 @nicolefurlan
14 months ago

Wonderful! @fotodrachen would you be willing to test PR 5430 5430.diff to see if the issue you reported here is resolved and submit a test report?

#25 @fotodrachen
14 months ago

Sorry, I can't do that. Actually I have no time, generally I did not have the skills.
But #comment:22 looks successfull for me.

#26 @oglekler
14 months ago

  • Milestone changed from 6.4 to 6.5

We still need more test reports and have only a day before RC1, so, even if the patch looks fine, I am moving this to the next milestone for proper testing.

This ticket was mentioned in Slack in #core-media by joedolson. View the logs.


14 months ago

This ticket was mentioned in Slack in #core-media by joedolson. View the logs.


11 months ago

#29 @antpb
11 months ago

  • Keywords needs-testing removed

Test Report

This report validates that the indicated patch addresses the issue.

Patch tested: https://github.com/WordPress/wordpress-develop/pull/5430

Environment

  • OS: macOS 14.2.1
  • Web Server: Nginx
  • PHP: 8.2
  • WordPress: 6.5-alpha-56966-src
  • Browser: Chrome 120.0.6099.199
  • Theme: Twenty Twenty-Four
  • Active Plugins:
    • None

Actual Results

  • ✅ Issue resolved with patch. Confirmed both with and without umlaut is working as intended.

Additional Notes

  • Confirmed new test changes were passing

Screenshots to follow

@antpb
11 months ago

without patch

@antpb
11 months ago

with patch without umlaut

@antpb
11 months ago

with patch with umlaut

#30 @joedolson
11 months ago

  • Keywords commit added

Thanks, @antpb! Marking for commit.

#31 @joedolson
11 months ago

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

In 57267:

Media: Fix handling of multibyte exif description metadata.

The exif standards expect the UserComment field to be used as a substitute for ImageDescription if multibyte characters are needed. WordPress media only mapped the ImageDescription field and did not correctly handle descriptions with multibyte characters.

Fix metadata saving to better handle media with multibyte characters in metadata and update unit tests.

Props fotodrachen, antpb, joedolson, mikinc860, azaozz, nicolefurlan.
Fixes #58082.

@joedolson commented on PR #5430:


11 months ago
#32

Fixed in r57267

Note: See TracTickets for help on using tickets.