ExifParser::encode(..) generates invalid Exif when used with Magick++
Added by Ray NA over 10 years ago
Hi,
I am manipulating ImageMagick Magick++ (mostly jpg) objects and I needed to update some of the Exif fields, which IM doesn't support so I am using exiv2 and then re-attaching the new exif data back into the IM object.
However, when I attach the encoded Exiv2::ExifData, I find that it is reported to be invalid/corrupt (verifiable via exiftool -v4). I came across [[http://dev.exiv2.org/boards/3/topics/250#message-251]] thread in the archives but no luck.
The fix I had to implement was to explicitly add the 'Exif\0\0' sequence to the Exiv2::Blob following the ExifParser::encode(). Can you tell me if this is expected behaviour or I am using the interface incorrectly?
I would have expected that the ExifParser::encode() method to create a buffer containing a valid Exif byte sequence. The following generates an updated exif as expected.
Magick::Image img("/tmp/foo.jpg");
Exiv2::Blob evraw;
Exiv2::ExifData evexif;
evexif["Exif.Image.Make"] = "my camera";
evexif["Exif.Image.Model"] = "model version";
Exiv2::ExifParser::encode(evraw, Exiv2::littleEndian, evexif);
uchar_t* ebuf = new uchar_t[6+evraw.size()];
ebuf[0] = 'E';
ebuf[1] = 'x';
ebuf[2] = 'i';
ebuf[3] = 'f';
ebuf[4] = 0;
ebuf[5] = 0;
memcpy(ebuf+6, &evraw[0], evraw.size());
img.exifProfile(Magick::Blob(ebuf, 6+evraw.size()));
delete [] ebuf;
img.write("/tmp/bar.jpg");
Replies (1)
RE: ExifParser::encode(..) generates invalid Exif when used with Magick++ - Added by Andreas Huggel over 10 years ago
The fix I had to implement was to explicitly add the 'Exif\0\0' sequence to the Exiv2::Blob following the ExifParser::encode(). Can you tell me if this is expected behaviour or I am using the interface incorrectly?
Yes, this is expected behaviour.
I would have expected that the ExifParser::encode() method to create a buffer containing a valid Exif byte sequence.
It does. The 'Exif\0\0' signature is a JPEG thing, it is used to identify the APP1 segment within a JPEG image which contains the Exif data. The result of ExifParser::encode() is also used for other image formats which do not all need the leading 'Exif\0\0'.
Andreas