Magick.NET
Magick.NET copied to clipboard
EXIF data not available
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
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?
You can use this one:
It should be reproducable with every image containing EXIF data I think.
image.GetExifProfile() does not return null with that test image (33806218-0fa8bb00-ddc5-11e7-8ba1-ac5c30401e63.jpg)?
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.
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.
That sounds great! It doesn't explain the PNG and TIF problem but those are good news anyway! Thank you very much!!
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.
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. :)
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.
Thank you very much for your efforts!
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/
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 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.
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.
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
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.
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/)
@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?
Please read my comments from earlier and I will now close this issue now because it seems to be hijacked for various things.