Magick.NET icon indicating copy to clipboard operation
Magick.NET copied to clipboard

EXIF data not available

Open 48design opened this issue 7 years ago • 17 comments

Hi,

I tried to use the EXIF data from my images but I do always get "null". With another library (MetadataExtractor, which is a bit oversized for me...) I can read the information so it is available.

The code used is the one found inside the documentation:

// Read image from file
using (MagickImage image = new MagickImage("FujiFilmFinePixS1Pro.jpg"))
{
  // Retrieve the exif information
  ExifProfile profile = image.GetExifProfile();

  // Check if image contains an exif profile
  if (profile == null)
    Console.WriteLine("Image does not contain exif information.");
  else
  {
    // Write all values to the console
    foreach (ExifValue value in profile.Values)
    {
      Console.WriteLine("{0}({1}): {2}", value.Tag, value.DataType, value.ToString());
    }
  }
}

profile is always null. Test image: https://www.48design.de/downloads/raw_images/raw_image.7z

48design avatar Dec 10 '17 11:12 48design

Do you also have a smaller test image that contains EXIF information that I could use in a unit test if this turns out to be a bug? Max 1mb? If you can point me to a location where I can download such a file that would also help a lot.

My guess is that this is happening because we added support for libraw recently and no longer need dcraw.exe. But I will need to run some tests before I can give you more information. Starting with which version do you suddenly get no exif profile?

dlemstra avatar Dec 10 '17 15:12 dlemstra

You can use this one: img_6777 It should be reproducable with every image containing EXIF data I think.

48design avatar Dec 10 '17 15:12 48design

image.GetExifProfile() does not return null with that test image (33806218-0fa8bb00-ddc5-11e7-8ba1-ac5c30401e63.jpg)?

dlemstra avatar Dec 10 '17 15:12 dlemstra

Oh, you are absolutely right! I've tested this with CR2, TIF and PNG but not with JPG... I tried it with the jpg and it really works! I didn't use it because of possible problems with artifacts. Shouldn't it work with other image formats? The library I mentioned above (MetadataExtractor) does read the information from the image file formats above.

48design avatar Dec 10 '17 17:12 48design

It should work with PNG and TIF as long as they have an exif profile. I did some research and it turns out we don't read the EXIF data when we decode the CR2 files. Will need to check if we can add support for that. I will get back to this issue when I know more.

dlemstra avatar Dec 10 '17 18:12 dlemstra

That sounds great! It doesn't explain the PNG and TIF problem but those are good news anyway! Thank you very much!!

48design avatar Dec 10 '17 18:12 48design

Could you add a PNG and a TIFF file that show that problem to this issue? Make sure you first check if they really have an exif profile.

EDIT: Just did a quick check of the exif profile parsing inside the TIFF reader and it appears we set them as an Attribute on the image. Wonder if and how we could change this. The PNG encoder does set the EXIF profile so it should work there.

dlemstra avatar Dec 10 '17 19:12 dlemstra

I've uploaded a TIF with EXIF information: IMG_6777_small.zip

I checked the PNGs again and it seems the EXIF information was indeed lost when converting from RAW, so there doesn't seem to be an issue. My research tells me that PNGs normally don't have EXIF information inside to this is not a problem on MagickNET's side. :)

48design avatar Dec 10 '17 19:12 48design

For the tiff format you will need to iterate through the image.AttributeNames and find the attributes thats start with "exif:" but you cannot get them as an ExifValue. And it looks like we only set dng: attributes for the RAW files at the moment. Already did some investigating into how we could parse the exif information but that won't be easy. Will need to do some more research when I have some free time to check this.

dlemstra avatar Dec 10 '17 21:12 dlemstra

Thank you very much for your efforts!

48design avatar Dec 11 '17 12:12 48design

First off thank you for your work!

Sample PNG File with EXIF data. http://imagemontage.com/preview/EXIFExample.png

CR2 files can be parse like TIFF file to access The EXIF data. Detail at: http://lclevy.free.fr/cr2/

flemingm avatar Jan 21 '18 03:01 flemingm

Sorry if I'm late to the game, and have missed something. According to this...

http://www.libpng.org/pub/png/pngnews.html

Exif is now a formal part of the PNG specification. It calls for a dedicated eXIf chunk for storing the exif data. In playing around with the latest version of Magick.NET, I've noticed that if I create an image, add an exif profile, set a value, and then save to a file, that the attribute is stored, but in a tEXT chunk. Also, if I reload that image, and call GetExifProfile, it returns null. I use Magick.NET for some of our image processing, and we're in the process of changing some things over from jpg to png. I can write some code for inserting the exif chunk myself, but obviously it would be great if Magick.NET had this built in. Have you guys done any work on the png encoder/decoder so that the exif profile would be maintained? If not, I'll probably be doing this myself and would happily contribute, I just don't want start something and find out in a week that you've already completed the work. Thanks for this, and for maintaining such a great library!

jackbond avatar May 18 '18 20:05 jackbond

@jackbond This issue is about adding support for reading exif information from a RAW file. ImageMagick reads and writes exif information inside PNG files so that should work. Could you open a new issue instead if you have problems with reading and writing exif information inside a PNG file? Please also include a sample so I can easily reproduce it.

dlemstra avatar May 19 '18 07:05 dlemstra

Yesterday I tried to read exif informations. I couldnt manage to do it in magick.net however when i try with exiftools i saw EXIF informations. I guess this issue opened years ago.

spinningcat avatar Apr 07 '20 08:04 spinningcat

Same for me, just tried code from first post with some random photos (NEF, ARW) which contains exif and GetExifProfile() always returns null. ImageMagick-7.1.0-Q8

TomQv avatar Nov 08 '21 23:11 TomQv

Adding support for reading EXIF information in raw files doesn't look like an easy task. There seems to be support for reading individual tags but that would mean we will need to "reconstruct" the exif profile.

dlemstra avatar Nov 22 '21 19:11 dlemstra

Trying to remove EXIF data:

      using (MagickImage image = new MagickImage(s))
      {
          var profile = image.GetExifProfile();
          if (profile != null)
          {
              image.RemoveProfile(profile.Name);
          }

          MemoryStream sOut = new MemoryStream();
          image.Write(sOut);

          return sOut;
      }

profile is null for the sample image provided above (https://user-images.githubusercontent.com/1440241/33806218-0fa8bb00-ddc5-11e7-8ba1-ac5c30401e63.jpg). However there is EXIF data there (verify here: http://exif-viewer.com/)

NVFedorov avatar Dec 17 '21 08:12 NVFedorov

@dlemstra Is not being able to read EXIF data from raw files a Magick.NET or ImageMagick limitation?

Can ImageMagick read individual EXIF values given their names?

kmgallahan avatar Aug 05 '23 01:08 kmgallahan

Please read my comments from earlier and I will now close this issue now because it seems to be hijacked for various things.

dlemstra avatar Aug 05 '23 12:08 dlemstra