February 25, 2009 | In: Programming, Wordpress

Nextgen gallery — exif data in lightbox effect

I wanted to dis­play some exif data under my pho­tos. I googled and googled and finally fig­ured out, see code below, it’s my copy of singlepic.php file in nextgen-gallery/view folder. At the moment only with sin­glepic, still work­ing to show it in albums. Any com­ments and cor­rec­tions 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="&lt; ?php echo $image-&gt;linktitle ?&gt;
 &lt; ?php echo $exif['camera'] ?&gt;,
 &lt; ?php echo $exif['aperture'] ?&gt; &amp; &lt; ?php echo $exif['shutter_speed'] ?&gt;,
 &lt; ?php echo $exif['focal_length'] ?&gt;,
 ISO &lt; ?php echo $exif['iso'] ?&gt;,
 &lt; ?php echo $exif['created_timestamp'] ?&gt;
 &lt; ?php echo $exif['flash'] ?&gt; " href="&lt;?php echo $image-&gt;imageURL ?&gt;">&lt; ?php echo $image-&gt;thumbcode ?&gt; &gt;
	<img class="&lt;?php echo $image-/&gt;classname ?&gt;" title="&lt; ?php echo $image-&gt;alttext ?&gt;" src="&lt; ?php echo $image-&gt;thumbnailURL ?&gt;" alt="&lt; ?php echo $image-&gt;alttext ?&gt;" />
</a>
&lt; ?php if (!empty ($image-&gt;caption)) : ?&gt;<span>&lt; ?php echo $image-&gt;caption ?&gt;</span>&lt; ?php endif; ?&gt;
 
&lt; ?php endif; ?&gt;

No related posts.

8 Responses to Nextgen gallery — exif data in lightbox effect

Avatar

Agung

March 9th, 2009 at 1:38 am  (Quote)

Hi, this is a great script!
but I found some­thing wrong, on line 26. Its writen “$image-/>classname” it should “$image->classname” (with­out the “/”)

and I want to aks, how do you put exif data in view­ing photo (lightbox)?

regards

Avatar

davejp

April 9th, 2009 at 12:58 pm  (Quote)

Thanks for post­ing this. It helped me fig­ure 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 pop­u­late the descrip­tion field with exif. sample:

http://​dave​.jp/​n​g​g​a​l​l​e​r​y​/​p​a​g​e​-​1​2​2​4​/​a​l​b​u​m​-​3​/​g​a​l​l​e​r​y-7

It now auto­mat­i­cally pop­u­lates new pho­tos descrip­tions and I just had to select “Import Meta data” for selected thumbs in the nextgen gallery admin panel to get the descrip­tions updated. It is sim­ple this way. I also added tags to descrip­tion and put more info into alt= for SEO.

in admin/functions.php go to
foreach($imagesIds as $pic_id) {
$pic­ture = 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) {
$pic­ture = nggdb::find_image($pic_id);
if (!$picture->error) {

$meta = nggAdmin::get_MetaData($picture->imagePath);

// get the title
if (!$alt­text = $meta[’title’])
$alt­text = ($meta[’keywords’] . ” ” . $meta[’camera’]);
// get the cap­tion / descrip­tion field
if (!$descrip­tion = $meta[’caption’])
$descrip­tion = ($meta[’exif_desc’] . “” . $meta[’keywords’]);
// get the file date/time from exif
$time­stamp = $meta[’timestamp’];
// update data­base
$result = $wpdb->query( $wpdb->prepare(“UPDATE $wpdb->nggpictures SET alt­text = %s, descrip­tion = %s, image­date = %s WHERE pid = %d”, $alt­text, $descrip­tion, $time­stamp, $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;

}

// **************************************************************
func­tion 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 updat­ing functions.php as above, upload a new image, or just click on a thumb in the gallery admin panel and select “import meta­data” from the drop down and click ok. You will see descrip­tion field update which should pop­u­late exif into light­box, or float­box in my case.

Avatar

Przemek

April 11th, 2009 at 1:12 pm  (Quote)

Thanks Dave for com­ment, your solu­tion works great.
BTW, great pho­tos at your website.

Avatar

KonstantinMiller

July 7th, 2009 at 4:48 am  (Quote)

I have been look­ing look­ing around for this kind of infor­ma­tion. Will you post some more in future? I’ll be grate­ful if you will.

Avatar

Chris

August 27th, 2009 at 5:00 pm  (Quote)

Hello,

How can this code be mod­i­fied for the fol­low­ing format:

Title
Author
Descrip­tion
Shut­ter, aper­ture, ISO

EG:
Morn­ing Rest
John Smith
A dewy drag­on­fly rests pur­ple loost­rife early in the morn­ing.
1/8 sec­ond, f8, ISO 100

Also, if these fields are blank, I’d like them left blank.
Chris

Avatar

Przemek

September 1st, 2009 at 8:33 am  (Quote)

@Chris
You have to check if exif func­tion can retrive fields you’ve wanted and replace code like < ?php echo $exif['camera'] ?> with code some­thing like < ?php echo $exif['author'] ?> and so on in singlepic.php file.
It’s just a guess, I can­not check it right now.

Prze­mek

Avatar

Brady Sammons

May 29th, 2010 at 6:44 pm  (Quote)

So I replaced all my code with yours, no errors, all appears well…I click the “import meta-data” but­ton, and I get a progress bar and dia­logue that says “action com­plete” how­ever when I view my page and click and on image and light box pops up i get no meta data??? I would really appre­ci­ate any help. Its for school thanks

Avatar

Przemek

May 30th, 2010 at 6:00 am  (Quote)

Brady,
Are you using my solu­tion (edit­ing singlepic.php) or dav­ejp one?

Comment Form