This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Writing Metadata

I tried to run the following code which is available in the site.

The code did run with out any problem and I can also open the created image using sample metadata application comes with the library.

But when I tried to open it with Photoshop I got the following error.
“unexpected end-of-file was encountered”

When I commented out metadata writing sections all seems to work fine.

It is very strange why the images can not be open with photoshop.

I would appriceate any advice on this matter.



            using (Aurigma.GraphicsMill.Bitmap bitmap = 
           new Aurigma.GraphicsMill.Bitmap(@"C:\Temp\zion-maple-1.jpg"))
            {
                Aurigma.GraphicsMill.Codecs.JpegEncoderOptions encoderOptions =
        new Aurigma.GraphicsMill.Codecs.JpegEncoderOptions(100, false);


                //EXIF
                Aurigma.GraphicsMill.Codecs.ExifDictionary exif =
        new Aurigma.GraphicsMill.Codecs.ExifDictionary();
                exif[Aurigma.GraphicsMill.Codecs.ExifDictionary.Software] = "Aurigma Graphics Mill";

                encoderOptions.Exif = exif;

                //IPTC
                Aurigma.GraphicsMill.Codecs.IptcDictionary iptc =
        new Aurigma.GraphicsMill.Codecs.IptcDictionary();
                iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Category] = "Nature";
                iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice] = "Aurigma Inc.";
                iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword] = "mountain";

                encoderOptions.Iptc = iptc;

                bitmap.Save(@"C:\Mountain2.jpg", encoderOptions);
            }

Hello,

We confirm the issue, there are some problems with saving IPTC. The update will be available with next release of Graphics Mill for .NET. If this issue is critical for you, please submit case.
Any good news on this issue guys?

Janaka
Hello Janaka,

The problem is in that IPTC specification doesn't allow category strings more than 3 symbols length. So if you replace line
iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Category] = "Nature";
by
iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Category] = "Nat";
everything works fine.

I have forwarded this issue to developer and the problem will be fixed - all category strings will be trimmed automatically while saving. To solve this problem with current compilation you should limit length of category strings by 3 symbols.
I have done the following to get the program working, since we don’t need all the IPTC fields.

So I manually set all the fields.

In our original images there is a field that shows the Image URL.

When you check from Photoshop it shows URL of client’s website. Since he sell images online it is very important that we set that field in all the images.

I could not find that field.

If I can set that field everything should be fine.

Can you tell how to access that field?

I really appreciate your effect in helping me.


Best regards,
Janaka


            Aurigma.GraphicsMill.Codecs.ExifDictionary exif = null;
            Aurigma.GraphicsMill.Codecs.IptcDictionary iptc = null;

            Aurigma.GraphicsMill.Codecs.JpegEncoderOptions encoderOptions = new Aurigma.GraphicsMill.Codecs.JpegEncoderOptions(70, false);

            using (Aurigma.GraphicsMill.Codecs.JpegReader jpegReader = new Aurigma.GraphicsMill.Codecs.JpegReader(strSourceFileName))
            {

                iptc            = jpegReader.Iptc;
                exif            = jpegReader.Exif;

            }

            if (exif == null)
            {
                exif = new Aurigma.GraphicsMill.Codecs.ExifDictionary();
            }
            
            
            if (iptc == null)
            {
                iptc = new Aurigma.GraphicsMill.Codecs.IptcDictionary();
            }

            encoderOptions.Iptc                             = new Aurigma.GraphicsMill.Codecs.IptcDictionary();

            try
            {

                encoderOptions.Iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Byline] = iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Byline];
                encoderOptions.Iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Caption] = iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.Caption];
                encoderOptions.Iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice] = iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.CopyrightNotice];
                encoderOptions.Iptc.SetItemArray(Aurigma.GraphicsMill.Codecs.IptcDictionary.Keyword, iptc.GetItemArray(IptcDictionary.Keyword));
                encoderOptions.Iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.ObjectName] = iptc[Aurigma.GraphicsMill.Codecs.IptcDictionary.ObjectName];
            }
            catch (Exception) { }

            encoderOptions.Exif = exif; 
Aurigma.GraphicsMill.Bitmap srcBitmap = new Aurigma.GraphicsMill.Bitmap(strSourceFileName);
srcBitmap.Save(strDest, encoderOptions);

Hello.

Adobe Photoshop image info fields are saved into several places of JPEG file. They are: EXIF, IPTC, Adobe Resources and XMP. Current compilation of Graphics Mill for .NET supports EXIF and IPTC only. Unfotunately Photoshop stores value of URL field into xapRights:WebStatement tag of XMP which is not supported at this moment.