getting arbitrary EXIF tags?

Alright, getting a little lost in the documentation and forums between various functions and methods to get EXIF vs IPTC vs internal data and whatnot.

Basically, I'm looking for a method to get an arbitrary EXIF tag from an image in zenphoto. Right now, specifically, that would be the 'ImageDescription' tag, but the question is more generic.

The tag seems to be represented in the exif.php (exifer), but I'm not quite spotting how to invoke that.

If I use getExifData(), I seem to only get a subset of the exif tags (make, model, various camera settings, etc.
If I use getImageMetaData, then I'm accessing the IPTC information; which is not where the information is stored in my case.

I'm probably missing something obvious, so feel free to just slap me with the URL to the docs :)

Thanks in advance!

Comments

  • Zenphoto uses the exifier script for extracting EXIF/IPTC data. But as you note, it extracts only a subset. (The description is extracted, by the way.) Look at the `getImageMetadata()` function in functions.php and/or the `getExifData()` method in class-image.php.

    Exifier itself does not necessarily process all tags so there may be some effort there as well. (If you add tag processing, let us know, we can then indclude them in the distribution.)
  • ZeBoxx Member
    yeah, that's the two functions I looked at;

    For...
    http://www.zenphoto.org/documentation/functions/_functions.php.html#functiongetImageMetadata
    The description reads that it parses IPTC information, rather than EXIF. This seems to be the case as well, as the only tag collected for my given image is (output of print_r on the array):
    Array ( [date] => 2009:06:25 04:10:30 )
    ( although ExifTool GUI seems to suggest that there's no IPTC data at all )

    While for...
    http://www.zenphoto.org/documentation/classes/_Image.html#getExifData
    The description reads only 'Returns an array of EXIF data'. The output of that is:
    Array ( [EXIFOrientation] => [EXIFMake] => Sony [EXIFModel] => DSC-V3 [EXIFExposureTime] => [EXIFFNumber] => [EXIFFocalLength] => [EXIFFocalLength35mm] => [EXIFISOSpeedRatings] => [EXIFDateTimeOriginal] => 2009:06:25 04:10:30 [EXIFExposureBiasValue] => [EXIFMeteringMode] => [EXIFFlash] => [EXIFImageWidth] => [EXIFImageHeight] => [EXIFContrast] => [EXIFSharpness] => [EXIFSaturation] => [EXIFWhiteBalance] => [EXIFSubjectDistance] => [EXIFGPSLatitude] => [EXIFGPSLatitudeRef] => [EXIFGPSLongitude] => [EXIFGPSLongitudeRef] => [EXIFGPSAltitude] => [EXIFGPSAltitudeRef] => )

    Which seems to suggest that ImageDescription isn't in the list. Note, however, that I've not yet upgraded to the latest and greatest (installed is 1.2.3 [3427]), so I'll have to grab that and see if it got added; otherwise I suspect I'd have to add it.

    Alternatively, just digging a little further, would I have to call read_entry from exif/exif.php manually?

    I'll hit the new version first :>
  • As I said, not all fields are extracted by Zenphoto. The reference to the functions was for you to see how they extracted fields so you could do your own.

    As for the IPTC, we will always get a date from somewhere--if just from the file--so there probably is not any IPTC data.

    I don't think any tags have been added recently.
  • ZeBoxx Member
    right, I just thought you meant that the description got extracted somewhere standard by default :)

    So it seems that something a la..
    [code]
    $metadata = read_exif_data_protected($_zp_current_image->localpath,0);
    echo $metadata['IFD0']['ImageDescription'];
    [/code]
    ..does the trick. Of course this is somewhat wasteful as it always accesses the image file, rather than the database. So my next step is to make things..

    [code]read image description from database
    |- if empty, read description from file
    | |- if empty, write 'No description' etc. per default
    | '- if not empty, use read result, and store in database
    '- if not empty, use read result[/code]

    This way any description in an image is automatically read, and if I want to override it with another description, I can do so using the existing mechanisms.
    Hooray :) *crosses fingers*
  • You could add this to the `$_zp_exifvars` array. Just remember to run setup.php after doing so. Then the description would be captured when the EXIF is processed.

    `'EXIFDescription' => array('IFD0', 'ImageDescription', gettext('Image Description'), false),`

    Let us know how it works. (Or create a ticket and attach an image which has this field set.)
  • ZeBoxx Member
    I figured that; but wouldn't that create a new column in the database for the description-as-captured-from-the-EXIF, rather than pre-filling the existing image description column ('desc')'s value?

    Which might not be so bad for a generic solution, but seems a tad on the wasteful side otherwise... would need the admin page to be updated to show the original description, or radiobuttons to show no/one/other/both descriptions, etc.?
  • Yes, it would create the new column. Then the data is available whenever and wherever you want it. Nothing is needed but adding that line (and of course using the data.) Everything triggers off that array. Adding the column really does not create any significant overhead unless the EXIF data is populated.

    It takes only a little more code to populate the title of the image from that field. (BTW, the EXIF 2.2. specification labels this field as "Image Title" even though it is tagged as ImageDescription.)

    Anyway, I've added this in the nightly build. It populates the title. Also added Copyright Holder and Artist since these seemed possibly useful. The latter are just available as imageMetadata fields.
  • ZeBoxx Member
    Cool, thanks Stephen - and yes, I'm using Copyright to show my Creative Commons license of choice, so it's very useful.

    One word of warning.. I just noticed that my camera actually fills in the ImageDescription field, by default, with 31 space characters. Exifer sees this as perfectly valid data, but I'd wager it's not typically what a user might want to have displayed. I added a preg_match("/\S/",$exifdesc) in my own code to check for any non-space characters before allowing it as a valid description (rather than title).
  • Thanks for the warning. I've added a trim to the field and use it only if it is then not empty. Still the title, though, since that is what the spec calls it.
  • ZeBoxx Member
    No problem :) Not sure if any other cameras do it, but I suspect some might via whatever API they use that always writes out certain data even if the camera doesn't (can't) supply it.

    yeah, I'm going against the spec... heck, the spec goes against the spec, really.. ImageDescription is the tag name, the spec says this is supposed to be the title, but obviously the tag name suggests otherwise.. on top of that, the spec specifies a maximum of 999 characters for it. A 999-character title? really? :>

    I do agree that zenphoto out-of-the-box should respect the spec, though.

    Thankfully zenphoto is easy enough to modify, which is why I chose to go with it (I run another gallery on the same domain for somebody else, using Gallery2... I can't make heads nor tails of that thing). Speaking of which, 'bout time I hit that Donate button :)

    Thanks again!
Sign In or Register to comment.