Unable to Read EXIF attributes from Image

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
cesareof
Posts: 11
Joined: 2011-03-25T08:12:07-07:00
Authentication code: 8675308

Unable to Read EXIF attributes from Image

Post by cesareof » 2013-04-04T10:21:55-07:00

I am attempting to read EXIF data from Images so I can store this information for later use and I am unable to read any attributes from the images I have. I downloaded and built the latest source for Windows ImageMagick-6.8.4 sucessfully, and when I run the provided application for viewing image info (identify.exe) it works fine:

Code: Select all

D:\common\ImageMagick-6.8.4\VisualMagick\bin>identify.exe -verbose d:\exif.jpg
Image: d:\exif.jpg
  Format: JPEG (Joint Photographic Experts Group JFIF format)
  Class: DirectClass
  Geometry: 3264x2448+0+0
  Resolution: 72x72
  Print size: 45.3333x34
  Units: PixelsPerInch
  Type: TrueColor
  Endianess: Undefined
  Colorspace: sRGB
  Depth: 8-bit
  Channel depth:
    red: 8-bit
    green: 8-bit
    blue: 8-bit
  Channel statistics:
    Red:
      min: 0 (0)
      max: 255 (1)
      mean: 109.709 (0.430231)
      standard deviation: 54.4065 (0.213359)
      kurtosis: -0.694073
      skewness: 0.288088
    Green:
      min: 0 (0)
      max: 255 (1)
      mean: 91.2706 (0.357924)
      standard deviation: 63.2079 (0.247874)
      kurtosis: -0.838898
      skewness: 0.540127
    Blue:
      min: 0 (0)
      max: 255 (1)
      mean: 79.2321 (0.310714)
      standard deviation: 65.8599 (0.258274)
      kurtosis: -0.0994204
      skewness: 0.905364
  Image statistics:
    Overall:
      min: 0 (0)
      max: 255 (1)
      mean: 93.4039 (0.36629)
      standard deviation: 61.3537 (0.240603)
      kurtosis: -0.491345
      skewness: 0.545162
  Rendering intent: Perceptual
  Gamma: 0.454545
  Chromaticity:
    red primary: (0.64,0.33)
    green primary: (0.3,0.6)
    blue primary: (0.15,0.06)
    white point: (0.3127,0.329)
  Background color: white
  Border color: srgb(223,223,223)
  Matte color: grey74
  Transparent color: black
  Interlace: None
  Intensity: Undefined
  Compose: Over
  Page geometry: 3264x2448+0+0
  Dispose: Undefined
  Iterations: 0
  Compression: JPEG
  Quality: 98
  Orientation: RightTop
  Properties:
    date:create: 2013-04-03T14:26:08-04:00
    date:modify: 2013-03-26T13:01:18-04:00
    exif:ApertureValue: 281/100
    exif:BrightnessValue: 497/100
    exif:ColorSpace: 1
    exif:Compression: 6
    exif:DateTime: 2013:03:26 13:00:13
    exif:DateTimeDigitized: 2013:03:26 13:00:13
    exif:DateTimeOriginal: 2013:03:26 13:00:13
    exif:ExifImageLength: 2448
    exif:ExifImageWidth: 3264
    exif:ExifOffset: 224
    exif:ExifVersion: 48, 50, 50, 48
    exif:ExposureBiasValue: 0/100
    exif:ExposureMode: 0
    exif:ExposureProgram: 3
    exif:ExposureTime: 1/50
    exif:Flash: 9
    exif:FlashPixVersion: 48, 49, 48, 48
    exif:FNumber: 265/100
    exif:FocalLength: 397/100
    exif:ImageLength: 2448
    exif:ImageUniqueID: OMEF01
    exif:ImageWidth: 3264
    exif:ISOSpeedRatings: 32
    exif:JPEGInterchangeFormat: 860
    exif:JPEGInterchangeFormatLength: 59136
    exif:Make: SAMSUNG
    exif:MakerNote: 5, 0, 1, 0, 7, 0, 4, 0, 0, 0, 48, 49, 48, 48, 2, 0, 4, 0, 1,
 0, 0, 0, 0, 32, 1, 0, 64, 0, 4, 0, 1, 0, 0, 0, 0, 0, 0, 0, 80, 0, 4, 0, 1, 0, 0
, 0, 1, 0, 0, 0, 0, 1, 3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
    exif:MaxApertureValue: 281/100
    exif:MeteringMode: 2
    exif:Model: GT-I9100
    exif:Orientation: 6
    exif:ResolutionUnit: 2
    exif:SceneCaptureType: 0
    exif:ShutterSpeedValue: 564/100
    exif:Software: I9100XXLPQ
    exif:thumbnail:Orientation: 6
    exif:thumbnail:ResolutionUnit: 2
    exif:thumbnail:XResolution: 72/1
    exif:thumbnail:YResolution: 72/1
    exif:UserComment: 65, 83, 67, 73, 73, 0, 0, 0, 85, 115, 101, 114, 32, 99, 11
1, 109, 109, 101, 110, 116, 115
    exif:WhiteBalance: 0
    exif:XResolution: 72/1
    exif:YCbCrPositioning: 1
    exif:YResolution: 72/1
    jpeg:colorspace: 2
    jpeg:sampling-factor: 2x1,1x1,1x1
    signature: ec1b7da9de8b91c89bc7e79d69965b05a07262054f5b0fb778a9e58a58504ae4
  Profiles:
    Profile-exif: 60002 bytes
  Artifacts:
    filename: d:\exif.jpg
    verbose: true
  Tainted: False
  Filesize: 3.692MB
  Number pixels: 7.99M
  Pixels per second: 10.23MB
  User time: 0.750u
  Elapsed time: 0:01.781
  Version: ImageMagick 6.8.4-6 2013-04-01 Q16 http://www.imagemagick.org
However when I attempt the same thing pragmatically, I am getting NULL for the values:

Code: Select all

void main()
{
	//-- ImageMagick
	InitializeMagick("D:\\common\\ImageMagick-6.8.4\\VisualMagick\\bin");

	char cInFile[MAX_PATH];
	char cOutFile[MAX_PATH];

	strcpy_s( cInFile, MAX_PATH, "d:\\exif.jpg" );

	Image img_test;
	img_test.read(cInFile);
	img_test.verbose(true);

	printf("DateTime: %s\n", img_test.attribute("EXIF:DateTime" ));
	printf("Make: %s\n", img_test.attribute("EXIF:Make" ));
	printf("Flash: %s\n", img_test.attribute("EXIF:Flash" ));
	printf("Compression: %s\n", img_test.attribute("EXIF:Compression" ));
	printf("XResolution: %s\n", img_test.attribute("EXIF:XResolution" ));
	printf("YResolution: %s\n", img_test.attribute("EXIF:YResolution" ));
	printf("MeteringMode: %s\n", img_test.attribute("EXIF:MeteringMode" ));
	printf("ExposureProgram: %s\n", img_test.attribute("EXIF:ExposureProgram" ));
	printf("ColorSpace: %s\n", img_test.attribute("EXIF:ColorSpace" ));
	printf("UserComment: %s\n", img_test.attribute("EXIF:UserComment" ));
	printf("ImageLength: %s\n", img_test.attribute("EXIF:ImageLength" ));
	printf("Orientation: %s\n", img_test.attribute("EXIF:Orientation" ));
	printf("ExposureTime: %s\n", img_test.attribute("EXIF:ExposureTime" ));
	printf("ApertureValue: %s\n", img_test.attribute("EXIF:ApertureValue" ));
	printf("ImageWidth: %s\n", img_test.attribute("EXIF:ImageWidth" ));
	printf("ISOSpeedRatings: %s\n", img_test.attribute("EXIF:ISOSpeedRatings" ));
	printf("ShutterSpeedValue: %s\n", img_test.attribute("EXIF:ShutterSpeedValue" ));
	printf("WhiteBalance: %s\n", img_test.attribute("EXIF:WhiteBalance" ));
}
Generates the following ouput:

Code: Select all

DateTime: (null)
Make: (null)
Flash: (null)
Compression: (null)
XResolution: (null)
YResolution: (null)
MeteringMode: (null)
ExposureProgram: (null)
ColorSpace: (null)
UserComment: (null)
ImageLength: (null)
Orientation: (null)
ExposureTime: (null)
ApertureValue: (null)
ImageWidth: (null)
ISOSpeedRatings: (null)
ShutterSpeedValue: (null)
WhiteBalance: (null)
What am I missing?

cesareof
Posts: 11
Joined: 2011-03-25T08:12:07-07:00
Authentication code: 8675308

Re: Unable to Read EXIF attributes from Image

Post by cesareof » 2013-04-09T07:19:40-07:00

Attempting to access FileInfo in this manner also doesn't seem to work:

Code: Select all

void main()
{
	//-- ImageMagick
	InitializeMagick("D:\\common\\ImageMagick-6.8.4\\VisualMagick\\bin");

	char cInFile[MAX_PATH];
	strcpy_s( cInFile, MAX_PATH, "d:\\exif.jpg" );

	Image img_test;
	img_test.read(cInFile);
	img_test.verbose(true);
	
	const MagickCore::ImageInfo *img_info = img_test.constImageInfo();
}
As the resulting ImageInfo structure is missing all of the information present when identify.exe is run.

I also attempted this method:

Code: Select all

void main()
{
	//-- ImageMagick
	InitializeMagick("D:\\common\\ImageMagick-6.8.4\\VisualMagick\\bin");

	char cInFile[MAX_PATH];
	strcpy_s( cInFile, MAX_PATH, "d:\\exif.jpg" );

	Image img_test;
	img_test.read(cInFile);
	img_test.verbose(true);
	
	Blob profile = img_test.profile("exif");
	MagickCore::ExceptionInfo *exception = MagickCore::AcquireExceptionInfo();
	MagickCore::BlobToFile("d:\\Blob.txt", profile.data(), profile.length(), exception );
}		
And it was equally ineffective as the resulting blob file starts with 'Exif II*' and the rest is seemingly useless garbage.
Any help pointing me in the right direction would be greatly appreciated.

cesareof
Posts: 11
Joined: 2011-03-25T08:12:07-07:00
Authentication code: 8675308

Re: Unable to Read EXIF attributes from Image

Post by cesareof » 2013-04-09T13:24:32-07:00

The Magick++ does not properly pull exif data easily, and I have been unable to determine how to use the library to that end.

I did find a pretty simple project that is easily included in your project to read exif data from an image, for anyone who is having a similar problem:

http://www.codeproject.com/Articles/380 ... sg=2764901

el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Unable to Read EXIF attributes from Image

Post by el_supremo » 2013-04-09T17:23:52-07:00

It worked for me once the std:string from attribute is converted to a C string.

Code: Select all

	printf("DateTime: %s\n",img_test.attribute("EXIF:DateTime" ).c_str());
Pete
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.

cesareof
Posts: 11
Joined: 2011-03-25T08:12:07-07:00
Authentication code: 8675308

Re: Unable to Read EXIF attributes from Image

Post by cesareof » 2013-04-11T12:25:54-07:00

That worked for me as well. Thanks.

Post Reply