Skip to content

IPTC tags written on jpg files that contains non-English characters can't be correctly displayed on external apps #2212

@lmerino-ep

Description

@lmerino-ep

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

2.1.3

Other ImageSharp packages and versions

None

Environment (Operating system, version and so on)

Windows 10 21H2

.NET Framework version

6

Description

The IPTC text tags on jpg files that contains non-English characters are displayed incorrectly on external apps, even though they are written using the default utf-8 encoding.

The use of utf-8 encoding is not indicated on the envelope record. External apps may use that record to identify the encoding and can assume the use of "ascii" encoding if not present.

I've written a patch that adds the optional tag (1:90 Coded Character Set) that indicates the use of utf-8 encoding on the text tags and solves this case. I can open a pull request or share the code with you.

Steps to Reproduce

  1. Load any jpg file.
  2. Write any text tag on IptcProfile, for example: Caption using non-English characters, such as "ESPAÑA".
  3. Save the changes on a new file.
  4. Open the new file with Irfanview, menu "Image -> Information", button "IPTC info".
  5. The caption tag shows "ESPAÑA" instead of "ESPAÑA".
 void Test()
        {
            const string fileInput = "c:\\temp\\input1.jpg"; // whatever jpg file
            const string fileOutput = "c:\\temp\\output1.jpg";

            using (SixLabors.ImageSharp.Image img = SixLabors.ImageSharp.Image.Load(fileInput))
            {
                if (img.Metadata.IptcProfile == null)
                {
                    img.Metadata.IptcProfile = new IptcProfile();
                }
                img.Metadata.IptcProfile.SetValue(IptcTag.Caption, "ESPAÑA");
                img.SaveAsJpeg(fileOutput, new JpegEncoder() { Quality = 90 });
            }
        }

This is the actual result:
wrong_iptc_irfanview

This is the expected result:
ok_iptc_irfanview

I've fixed this adding the 1:90 "Coded Character Set" to the Envelope record on IptcProfile.UpdateData() method.

Images

input1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions