Crit My Code, automagic php Lightbox2web gallery code.

Associate
Joined
3 Sep 2003
Posts
1,699
Getting fed up with the bloat required for running a gallery2 set up on my website I have spent a few evenings to come up with this code which browses an album of images, adds each image to a table with the appopriate thumbnail as an image link to lightbox2. Lightbox2 image title is read from the jpegs exif comment tag.

PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<!Lightbox2 info>
<script type="text/javascript" src="../js/prototype.js"></script>
<script type="text/javascript" src="../js/scriptaculous.js?load=effects"></script>
<script type="text/javascript" src="../js/lightbox.js"></script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Landscapes</title>
<link href="../css/main.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="../css/lightbox.css" type="text/css" media="screen" />
<!--[if lte IE 7]><script src="/include/optionDisabledSupport.js" type="text/javascript"></script><![endif]-->
</head>

<body>
<div id="container"><!-- #BeginLibraryItem "/Library/NavBar.lbi" --><div id="navbarcontainer">
<div id="navbar">
<ul>
<li><a href="/index.php">Home</a></li>
<li><a href="/pages/about.html">About</a></li>
<li><a href="/pages/galleries.php">Galleries</a></li>
</ul>
</div> <!-- navbar -->
</div> <!-- navbarcontainer --><!-- #EndLibraryItem --><div id="portfolio">
<!PHP Table Script>
<div align="center"><center>
<?php

include('../includes/exif.php');

$a = '0';
$filepath = "../albums/landscapes/thumbs";
$url_path = "../albums/landscapes/";
$album_name = "landscapes";
$dir = dir($filepath);
echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"5\" width=\"75%\">";
while($entry=$dir->read()) {
    if($entry == "." || $entry == "..") {
        continue;
    }
    $fp = @fopen("$filepath/$entry","r");
if ($a == '0') {echo "<tr>";}
if ($a == '5') {echo "<tr>";}
if ($a == '10') {echo "<tr>";}
if ($a == '15') {echo "<tr>";}
$exifdata = read_exif_data_raw("$url_path/$entry",0);	

$caption = $exifdata[IFD0][ImageDescription];
?><td>
  <a href="<? echo "$url_path/$entry" ?>"rel ="lightbox[<? echo "$album_name" ?>]" title="<? echo "$caption" ?>">
  <img src="<? echo "$filepath/$entry" ?>" alt="<? echo "$caption"?>"></a>
  </td>
<?
$a = $a + 1;
}
?>
</tr>
</table>
</center></div>
</body>
</html>

A demo can be seen here:

http://www.brianinnesphotography.co.uk/pages/landscapes.php

Don't try clicking any of the other page links as they aren't up yet. At the moment the page is just a rough test of the code.

If anyone would be kind enough to take a look at the code and check I've not done anything daft (I don't have access to other OS web browsers to check compatibility). Is there a better / easier way to achieve what I want to do?

Thanks in advance.
 
where has the close button gone?

I am very interested in your work that you have done here for my website.

Do you mind sending me the files? I will give you a link to your site if you like.

what is in the exif.php file?
 
Last edited:
where has the close button gone?

I am very interested in your work that you have done here for my website.

Do you mind sending me the files? I will give you a link to your site if you like.

what is in the exif.php file?

The close button is a mystery!

I can't take much credit as the code is a mish mash of php code I found on google. The exif.php file is here:
http://http://www.zenphoto.org/svn/trunk/zp-core/exif/exif.php as the php version
on my web server hasn't been compiled with exif read support.

Still a bit to add, like display the image exif info if present.

I'll probably make the code available once it's finished. :)
 
Off topic: WTF is up with the background colour in the PHP code tag - I'm squinting and tilting my laptop screen here just to try and read the code...:rolleyes:
 
Would it be possible to have the caption as a php include text file so that each picture has a caption stored in separate text files instead of the exif.

Do I make sense?
 
Would it be possible to have the caption as a php include text file so that each picture has a caption stored in separate text files instead of the exif.

Do I make sense?

Thats a possibility.
However for my purposes I want to do the least amount of editing of files. The image captions I add in exif so that I can do all of that in photo management program (digikam), then it's simply a case of copying the photos to the web!
 
Thats a possibility.
However for my purposes I want to do the least amount of editing of files. The image captions I add in exif so that I can do all of that in photo management program (digikam), then it's simply a case of copying the photos to the web!

Hmmm, not sure if exif info is W3C WAI compatible...
 
Hmmm, not sure if exif info is W3C WAI compatible...

well if it isn't.. it should be :rolleyes:

i do exactly the same, my script scans a dir for jpgs, then loops round creating links for lightbox, and thumbnails. It gets the alt text and lightbox caption from the exif data. having a seperate text file for each comment would be stuipd imo, i wrote my script to save time / effort when adding images to the gallerys - having a thousand little text files is daft.

http://urban404.net/kidderminsterSugar_gallery.php
 
well if it isn't.. it should be :rolleyes:

i do exactly the same, my script scans a dir for jpgs, then loops round creating links for lightbox, and thumbnails. It gets the alt text and lightbox caption from the exif data. having a seperate text file for each comment would be stuipd imo, i wrote my script to save time / effort when adding images to the gallerys - having a thousand little text files is daft.

http://urban404.net/kidderminsterSugar_gallery.php

Does your script cache the thumbnails? Any chance you could share the thumbnail generation code as it could be handy for my site rather than manually create the thumbnails on my machine then upload them to my server.
 
Back
Top Bottom