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

Notification

Icon
Error

Options
Go to last post Go to first unread
bma  
#1 Posted : Thursday, May 5, 2016 7:10:46 AM(UTC)
bma

Rank: Member

Groups: Guest
Joined: 1/12/2016(UTC)
Posts: 23

Thanks: 8 times
Hello,

I have an image with Exif and IPTC, however when I try to convert the image from tiff to jpeg, I get the following errors:

1. EXIF data object is too big, its size exceeds 64K limit (that is defined by Jpeg standart for APP1 marker data).

2. The graphics mill doesn't recognize the iptc, therefore I can't export the image to jpeg with IPTC.

Can you provide more information about this?

Link to the picture mentioned above: https://www.dropbox.com/...2100707612_C1C1.tif?dl=0

Please see the pictures attached.

Sample code:

Code:

using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Codecs.Psd;
using System.IO;

namespace GraphicsMill_Tests
{
    public class Program
    {
        public static void Main(string[] args)
        {
            const string path = @"148759_08712100707612_C1C1.tif";
            const string pathOutput = @"teste.jpg";

            var file = File.ReadAllBytes(path);

            using (var imageStream = new MemoryStream(file))
            using (var exportedImageStream = new MemoryStream())
            using (var imageReader = ImageReader.Create(imageStream))
            using (var bitmap = imageReader.Frames[0].GetBitmap())
            {
                // merge photoshop layers
                if (imageReader.FileFormat == FileFormat.Psd)
                    ((PsdReader)imageReader).MergeLayers(bitmap);

                var jpegSettings = new JpegSettings { Quality = 85 };

                if (imageReader.AdobeResources != null)
                {
                    jpegSettings.AdobeResources = imageReader.AdobeResources;
                }

                if (imageReader.Exif != null)
                {
                    jpegSettings.Exif = imageReader.Exif;
                }

                if (imageReader.Iptc != null)
                {
                    jpegSettings.Iptc = imageReader.Iptc;
                }

                if (imageReader.Xmp != null)
                {
                    jpegSettings.Xmp = imageReader.Xmp;
                }

                bitmap.Save(exportedImageStream, jpegSettings);

                File.WriteAllBytes(pathOutput, exportedImageStream.GetBuffer());
            }
        }
    }
}

Kind Regards

Edited by user Thursday, May 5, 2016 7:11:20 AM(UTC)  | Reason: Not specified

bma attached the following image(s):
exif.png
iptc.png
Fedor  
#2 Posted : Tuesday, May 10, 2016 3:47:35 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Quote:
1. EXIF data object is too big, its size exceeds 64K limit (that is defined by Jpeg standart for APP1 marker data).

The Exif metadata is stored in TIFF and JPEG files differently. The Exif data stored in JPEG is limited by 64KB (maximum size of the JPEG APP1 marker). That's why you receive the exception. We need to make a research to see how to handle this problem (Aurigma Bug #0022166). Most probably it is necessary to write to other APPN markers, but we should check this idea first.

Meanwhile, you can try to fix the problem by reducing an Exif data size. For example, you can remove thumbnail (which is typically the largest piece of Exif data). Unfortunately, we don't know the Exif size before saving. That's why the simplest way to do it is to catch an exception:

Code:
using Aurigma.GraphicsMill.Codecs;
using Aurigma.GraphicsMill.Codecs.Psd;
using System.IO;

namespace Forum_14044
{
	public class Program
	{
		public static void Main(string[] args)
		{
			const string path = @"../../../148759_08712100707612_C1C1.tif";
			const string pathOutput = @"../../../teste.jpg";

			var file = File.ReadAllBytes(path);

			using (var imageStream = new MemoryStream(file))
			using (var exportedImageStream = new MemoryStream())
			using (var imageReader = ImageReader.Create(imageStream))
			using (var bitmap = imageReader.Frames[0].GetBitmap())
			{
				// merge photoshop layers
				if (imageReader.FileFormat == FileFormat.Psd)
					((PsdReader)imageReader).MergeLayers(bitmap);

				var jpegSettings = new JpegSettings { Quality = 85 };

				if (imageReader.AdobeResources != null)
				{
					jpegSettings.AdobeResources = imageReader.AdobeResources;
				}

				if (imageReader.Exif != null)
				{
					jpegSettings.Exif = imageReader.Exif;
				}

				if (imageReader.Iptc != null)
				{
					jpegSettings.Iptc = imageReader.Iptc;
				}

				if (imageReader.Xmp != null)
				{
					jpegSettings.Xmp = imageReader.Xmp;
				}

				try
				{
					bitmap.Save(exportedImageStream, jpegSettings);
				}
				catch (JpegMarkerException ex)
				{
					if (ex.Message.IndexOf("64K limit") != -1 
						&& jpegSettings.Exif != null  && jpegSettings.Exif[ExifDictionary.Thumbnail] != null)
					{
						jpegSettings.Exif.Remove(ExifDictionary.Thumbnail);

						bitmap.Save(exportedImageStream, jpegSettings);
					}
					else
					{
						throw ex;
					}
				}

				File.WriteAllBytes(pathOutput, exportedImageStream.GetBuffer());
			}
		}
	}
}

Quote:
2. The graphics mill doesn't recognize the iptc, therefore I can't export the image to jpeg with IPTC.

We confirm the problem (Aurigma Bug #0022163). I have added it to the roadmap. We will fix it in within next 3-4 weeks. Thank you for catching it!

Edited by moderator Tuesday, May 10, 2016 3:57:36 AM(UTC)  | Reason: Not specified

Best regards,

Fedor Skvortsov

bma  
#3 Posted : Monday, May 16, 2016 1:28:25 AM(UTC)
bma

Rank: Member

Groups: Guest
Joined: 1/12/2016(UTC)
Posts: 23

Thanks: 8 times
Thank you!

Keep me posted about this issue.

Kind regards

Fedor  
#4 Posted : Tuesday, May 17, 2016 10:48:44 PM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Quote:
2. The graphics mill doesn't recognize the iptc, therefore I can't export the image to jpeg with IPTC.

We checked the problem and here is a result of our research.

  1. When you open the 148759_08712100707612_C1C1.tif file in Photoshop you can see that the Creator and Description fields on the IPTC tab are filled.

  2. Graphics Mill doesn't recognize the IPTC metadata in the 148759_08712100707612_C1C1.tif file, and therefore the teste.jpg file does not have IPTC data at all. The ExifTool software doesn't read IPTC as well.

  3. Despite this fact, Photoshop displays the non-empty Creator and Description IPTC fields for teste.jpg (it does not have IPTC data as noted above!)

It looks like this TIFF file does not have IPTC indeed, and Adobe Photoshop reads the Creator and Description fields from the appropriate EXIF fields. For some reasons, Adobe made it a bit misleading.

So you can also search for your values in EXIF if there is no IPTC data. Or, you can even copy these EXIF fields to the IPTC, like this:

Code:
if (imageReader.Iptc != null)
{
	jpegSettings.Iptc = imageReader.Iptc;
}
else if (imageReader.Exif.Contains(ExifDictionary.ImageDescription)
		|| imageReader.Exif.Contains(ExifDictionary.Artist))
{
	var iptc = new IptcDictionary();
	iptc.Add(IptcDictionary.Caption, imageReader.Exif[ExifDictionary.ImageDescription]);
	iptc.Add(IptcDictionary.Byline, imageReader.Exif[ExifDictionary.Artist]);

	jpegSettings.Iptc = iptc;
}

So it seems this problem is not a bug and doesn't require any further actions. Let me know if you still have any questions/problems.

Edited by moderator Tuesday, May 17, 2016 11:11:17 PM(UTC)  | Reason: Not specified

Fedor attached the following image(s):
photoshop_iptc.png
Best regards,

Fedor Skvortsov

Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.