This project has moved. For the latest updates, please go here.

IPTC data unreadable

Feb 24, 2015 at 2:06 PM
Hello!

I have some code which takes a source image, adds / updates metadata tags, writes it to disk, then reopens the file several times to create clones of different sizes / watermarks.

I've got a file here that's had some metadata tags added by Magick.NET where it seems fine if I try using a metadata viewer to read them, but when I try to reopen the file using var img = new MagickImage(filename), the image IPTC metadata is no longer present in the object.

Can I send you a copy of this file to take a look at it, please? If so, it's a 10MB .tif file which I don't think the owners would like me releasing anywhere public, so - how can I send it to you privately?
Coordinator
Feb 24, 2015 at 2:55 PM
Contact me through CodePlex and I will get your e-mail. I can then reply to that so you can get mine.
Feb 24, 2015 at 3:01 PM
I've done a bit more testing, and I think that this issue only occurs if I have written a new IPTC profile to the image.

i.e.

If the file had an IPTC profile before, and I edit the image and write to a file, I can load the file into a MagickImage object and it retains the edits.

If the file had no IPTC profile, so I create a new IptcProfile() and set values to it, then add that to the image, and write it to a file - when I later load the file into a new MagickImage object, it cannot load the IPTC profile.

I also found that if I edit the image to being a plain single colour image, it still does the same thing, so no need for me to worry about release issues. :)
Feb 24, 2015 at 3:12 PM
https://drive.google.com/file/d/0B6wQHfPogTpcUlpLQV94R2NaMmc/view

Here's a sample file (001.tif) with IPTC data which was created through Magick.net - and the IPTC data is readable if I open it in PhotoME... but is not present if I do image.GetIptcProfile() on it.
Coordinator
Feb 24, 2015 at 3:15 PM
What is the exact version of Magick.NET that you are using?
Feb 24, 2015 at 3:21 PM
Magick.NET-Q16-AnyCPU
Version 7.0.0.0009
Coordinator
Feb 24, 2015 at 4:12 PM
And can you provide me with a code sample that you used to create the IptcProfile for the file '001.tif'?
Feb 24, 2015 at 4:16 PM

        public void ApplyMetaDataToImageFile(string imageFilePath)
        {
            using (var image = new MagickImage(imageFilePath))
            {
                var imageWithMeta = ApplyMetaDataToImage(image);
                imageWithMeta.Write(imageFilePath);
            }
        }

        public MagickImage ApplyMetaDataToImage(MagickImage image)
        {
            IptcProfile iptcProfile = GetUpdatedIptcProfile(image);
            ExifProfile exifProfile = GetupdatedExifProfile(image);
            XmpProfile xmpProfile = GetUpdatedXmpProfile(image);

            if (iptcProfile != null)
            {
                image.AddProfile(iptcProfile);
            }

            if (exifProfile != null)
            {
                image.AddProfile(exifProfile);
            }

            if (xmpProfile != null)
            {
                image.AddProfile(xmpProfile);
            }
            return image;
        }

        private IptcProfile GetUpdatedIptcProfile(MagickImage image)
        {
            IptcProfile iptcProfile = image.GetIptcProfile() ?? new IptcProfile();

            iptcProfile.SetValue(IptcTag.Byline, Creator);
                // Alternative label advocated by the older IPTC IIM schema, used for "Creator."
            iptcProfile.SetValue(IptcTag.Headline, Headline);
            iptcProfile.SetValue(IptcTag.CopyrightNotice, CopyrightNotice);
            return iptcProfile;
        }
Coordinator
Feb 24, 2015 at 10:17 PM
Edited Feb 24, 2015 at 10:23 PM
I just added a unit test to Magick.NET and I can reproduce the issue. It looks like a problem in the TIFF writer/reader. It does work when the output format is PNG. This is most likely a bug in ImageMagick. I will investigate this later this week/weekend.
Feb 24, 2015 at 10:45 PM
Thank you!