I wanted to display some exif data under my photos. I googled and googled and finally figured out, see code below, it’s my copy of singlepic.php file in nextgen-gallery/view folder. At the moment only with singlepic, still working to show it in albums. Any comments and corrections appreciated.
< ?php /** Template Page for the single pic Follow variables are useable : $image : Contain all about the image $meta : Contain the raw Meta data from the image $exif : Contain the clean up Exif data $iptc : Contain the clean up IPTC data $xmp : Contain the clean up XMP data You can check the content when you insert the tag If you would like to show the timestamp of the image ,you can use < ?php echo $exif['created_timestamp'] ?> **/ ?> < ?php if (!defined ('ABSPATH')) die ('No direct access allowed'); ?>< ?php if (!empty ($image)) : ?> <a title="< ?php echo $image->linktitle ?> < ?php echo $exif['camera'] ?>, < ?php echo $exif['aperture'] ?> & < ?php echo $exif['shutter_speed'] ?>, < ?php echo $exif['focal_length'] ?>, ISO < ?php echo $exif['iso'] ?>, < ?php echo $exif['created_timestamp'] ?> < ?php echo $exif['flash'] ?> " href="<?php echo $image->imageURL ?>">< ?php echo $image->thumbcode ?> > <img class="<?php echo $image-/>classname ?>" title="< ?php echo $image->alttext ?>" src="< ?php echo $image->thumbnailURL ?>" alt="< ?php echo $image->alttext ?>" /> </a> < ?php if (!empty ($image->caption)) : ?><span>< ?php echo $image->caption ?></span>< ?php endif; ?> < ?php endif; ?> |
Hi, this is a great script!
but I found something wrong, on line 26. Its writen “$image-/>classname” it should “$image->classname” (without the “/”)
and I want to aks, how do you put exif data in viewing photo (lightbox)?
regards
Thanks for posting this. It helped me figure out how to solve my exif problem.
I wanted to do this in my nextgen gallery as well. I decided I wanted the exif to show in lightbox/floatbox when a viewer clicks a thumb, so I updated functions.php to populate the description field with exif. sample:
http://dave.jp/nggallery/page-1224/album-3/gallery-7
It now automatically populates new photos descriptions and I just had to select “Import Meta data” for selected thumbs in the nextgen gallery admin panel to get the descriptions updated. It is simple this way. I also added tags to description and put more info into alt= for SEO.
in admin/functions.php go to
foreach($imagesIds as $pic_id) {
$picture = nggdb::find_image($pic_id);
if (!$picture->error) {
$meta = nggAdmin::get_MetaData($picture->imagePath);
I changed mine to look like this:
foreach($imagesIds as $pic_id) {
$picture = nggdb::find_image($pic_id);
if (!$picture->error) {
$meta = nggAdmin::get_MetaData($picture->imagePath);
// get the title
if (!$alttext = $meta[’title’])
$alttext = ($meta[’keywords’] . ” ” . $meta[’camera’]);
// get the caption / description field
if (!$description = $meta[’caption’])
$description = ($meta[’exif_desc’] . “” . $meta[’keywords’]);
// get the file date/time from exif
$timestamp = $meta[’timestamp’];
// update database
$result = $wpdb->query( $wpdb->prepare(“UPDATE $wpdb->nggpictures SET alttext = %s, description = %s, imagedate = %s WHERE pid = %d”, $alttext, $description, $timestamp, $pic_id) );
// add the tags
if ($meta[’keywords’]) {
$taglist = explode(‘,’, $meta[’keywords’]);
wp_set_object_terms($pic_id, $taglist, ‘ngg_tag’);
} // add tags
}// error check
} // foreach
return true;
}
// **************************************************************
function get_MetaData($picPath) {
// must be Gallery absPath + filename
require_once(NGGALLERY_ABSPATH . ‘/lib/meta.php’);
$meta = array();
$pdata = new nggMeta($picPath);
$meta[’title’] = $pdata->get_META(‘title’);
$meta[’caption’] = $pdata->get_META(‘caption’);
$meta[’keywords’] = $pdata->get_META(‘keywords’);
$meta[’timestamp’] = $pdata->get_date_time();
$meta[’exif_desc’] = ($pdata->get_META(‘camera’) . “, ” . $pdata->get_META(‘focal_length’) . “, ” . $pdata->get_META(‘shutter_speed’) . “, ” . $pdata->get_META(‘aperture’) . “, ISO ” . $pdata->get_META(‘iso’) . “, ” . $pdata->get_META(‘created_timestamp’));
return $meta;
}
after updating functions.php as above, upload a new image, or just click on a thumb in the gallery admin panel and select “import metadata” from the drop down and click ok. You will see description field update which should populate exif into lightbox, or floatbox in my case.
Thanks Dave for comment, your solution works great.
BTW, great photos at your website.
I have been looking looking around for this kind of information. Will you post some more in future? I’ll be grateful if you will.
Hello,
How can this code be modified for the following format:
Title
Author
Description
Shutter, aperture, ISO
EG:
Morning Rest
John Smith
A dewy dragonfly rests purple loostrife early in the morning.
1/8 second, f8, ISO 100
Also, if these fields are blank, I’d like them left blank.
Chris
@Chris
You have to check if exif function can retrive fields you’ve wanted and replace code like
< ?php echo $exif['camera'] ?>with code something like< ?php echo $exif['author'] ?>and so on in singlepic.php file.It’s just a guess, I cannot check it right now.
Przemek
So I replaced all my code with yours, no errors, all appears well…I click the “import meta-data” button, and I get a progress bar and dialogue that says “action complete” however when I view my page and click and on image and light box pops up i get no meta data??? I would really appreciate any help. Its for school thanks
Brady,
Are you using my solution (editing singlepic.php) or davejp one?