Project

General

Profile

Writing GPano XMP metadata

Added by Emanuel Jöbstl over 4 years ago

Hello all,

I'm trying to add GPano XMP metadata to an image. I use the following code:

    Exiv2::XmpProperties::registerNs("http://ns.google.com/photos/1.0/panorama/", "GPano");
    Exiv2::XmpData xmpData;

    xmpData["Xmp.GPano.UsePanoramaViewer"] = boolean_t(true);
    xmpData["Xmp.GPano.ProjectionType"] = "equirectangular";
    xmpData["Xmp.GPano.FullPanoWidthPixels"] = uint32_t(width);
    xmpData["Xmp.GPano.FullPanoHeightPixels"] = uint32_t(width / 2);
    xmpData["Xmp.GPano.CroppedAreaLeftPixels"] = uint32_t(0);
    xmpData["Xmp.GPano.CroppedAreaTopPixels"] = uint32_t((width - height) / 2);
    xmpData["Xmp.GPano.CroppedAreaImageWidthPixels"] = uint32_t((width - height) / 2);
    xmpData["Xmp.GPano.CroppedAreaImageHeightPixels"] = uint32_t((width - height) / 2);

    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(strPath);
    assert(image.get() != 0);
    image->setXmpData(xmpData);
    image->writeMetadata();

However, the resulting image does not contain any xmp data at all. No exception is thrown. The path is also correct, for example writing Exif.Image.Model works.

What am I missing here?

Emanuel


Replies (3)

RE: Writing GPano XMP metadata - Added by Robin Mills over 4 years ago

The code looks "almost" correct to me. You don't need to register GPano as it's already known to exiv2:

510 rmills@rmillsmbp:~ $ exiv2 -vV | grep -i pano
xmlns=GPano:http://ns.google.com/photos/1.0/panorama/
511 rmills@rmillsmbp:~ $ 
So you can set it directly:
511 rmills@rmillsmbp:~ $ cp Stonehenge.jpg  S.jpg
512 rmills@rmillsmbp:~ $ exiv2 -px S.jpg 
Xmp.xmp.Rating                               XmpText     1  0
Xmp.xmp.ModifyDate                           XmpText    25  2015-07-16T20:25:28+01:00
Xmp.dc.description                           LangAlt     1  lang="x-default" Classic View
513 rmills@rmillsmbp:~ $ exiv2 -M'set Xmp.GPano.ProjectionType myProjectionType' S.jpg 
514 rmills@rmillsmbp:~ $ exiv2 -px S.jpg 
Xmp.xmp.Rating                               XmpText     1  0
Xmp.xmp.ModifyDate                           XmpText    25  2015-07-16T20:25:28+01:00
Xmp.GPano.ProjectionType                     XmpText    16  myProjectionType
Xmp.dc.description                           LangAlt     1  lang="x-default" Classic View
515 rmills@rmillsmbp:~ $ 
I don't believe that setting the NS would cause your code to fail to write. JPGImage::writeMetadata uses the XMPsdk to serialise the XMP as XML and it's written to the image. Try debugging this. If you get stuck, let me know and I'll investigate more throughly.

I also encourage you to use the exiv2 command-line program before working with the API. If you can obtain the result you want, you can debug to discover exactly how the result is obtained.

RE: Writing GPano XMP metadata - Added by Emanuel Jöbstl over 4 years ago

Thanks for your fast reply!

I switched to Apple's ImageIO for now (I was working on an iOS). I will pick up this task on a later point, where I will need to write extended XMP.

RE: Writing GPano XMP metadata - Added by Robin Mills over 4 years ago

Well good luck with that. A few years ago, I compared the speed of Exiv2 with Apple Objective-C/NSImage. Exiv2 is about 100x faster because we don't build a frame buffer. We only read the metadata. However, unless you're working on hundreds of images, the performance difference is probably of little concern in an iOS application. The convenience of calling Apple's image code is probably more interesting to you than performance. I have no idea about your application and if you have to build a frame buffer, you may need to read the whole image anyway. However Exiv2 can efficiently load thumbnails and metadata which might enable your application to start up more quickly and save bandwidth when accessing remote images.

    (1-3/3)