Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
4 tasks done
lmerino-ep opened this issue Aug 22, 2022 · 1 comment · Fixed by #2213

Comments

@lmerino-ep
Copy link
Contributor

lmerino-ep commented Aug 22, 2022

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

@tocsoft
Copy link
Member

tocsoft commented Aug 22, 2022

@lmerino-ep thanks for finding this. Please feel free to open a PR with the fix.

lmerino-ep added a commit to lmerino-ep/ImageSharp that referenced this issue Aug 23, 2022
brianpopow added a commit that referenced this issue Aug 24, 2022
Fix IPTC tags written on jpg files that contains non-English characters can't be correctly displayed on external apps #2212
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants