Posted By

trepmal on 07/31/10


Tagged


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

Priestd09


Image Browser


 / Published in: HTML
 

URL: http://trepmal.com/scripts/image-browser/

Sometimes a client will provide a bunch of photos – which is great – but when they’re in a bunch of different folders, it can be hard to sort through and find the right one. So, just toss your web-friendly photos into a directory on their website, and use the script below to nicely display all the photos.\r\n\r\nIt makes thumbnails (with my ThumbFly script from earlier) and saves them to a temp directory for caching. Photos are sorted by sub-directory, and the image name is revealed on hover. It’s easy to make this script modal-box friendly.

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml">
  3. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  4. <title>Image Browser</title>
  5. <style type="text/css">
  6. <!--
  7. *{margin:0;padding:0;outline:0;}
  8. .clear{clear:both;}
  9. h2 {clear:both;margin: 5px 0 20px 0;background:#f3f3f3;padding:3px;border: 1px solid #555;}
  10. body {background:#292929;text-align:center;font-size: 62.5%;font-family:Verdana, Geneva, sans-serif;}
  11. #page {background:#fff; width:960px;margin: 20px auto;padding:20px;text-align:left;overflow:hidden;}
  12. a {display:block;width:125px;height:125px;overflow:hidden;margin:3px;float:left;position:relative;border: 1px solid #555;}
  13. a span {position:absolute;bottom:200px;left:0px;width:125px;background:#ccc;line-height:14px;}
  14. a:hover span {bottom:0px;}
  15. a img {border:none;}
  16. -->
  17. <link rel="stylesheet" type="text/css" href="css/colorbox.css" />
  18. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
  19. <script type="text/javascript" src="js/jquery.colorbox-min-1.3.6.js"></script>
  20. <script type="text/javascript">
  21. $(document).ready(function(){
  22. $("a[href$='jpg']").colorbox();
  23. });
  24. <body id="home">
  25. <div id="page">
  26. Click to enlarge.
  27. <?php
  28.  
  29. function get_imgs($type) {
  30. $i = '0';
  31. foreach(glob("*.$type") as $img) {
  32. echo '<a href="'.$img.'" title="'.$img.'" rel="'.$dir.'" class="popup">';
  33. echo '<img src="'.thumbfly( array( 'src' => $img, 'w' => 125, 'h' => 125 ) ). '" title="'.$img.'" />';
  34. echo '<span>'.$img.'</span>';
  35. echo '</a>'."\n";
  36. ++$i;
  37. }
  38. foreach(glob("*/",GLOB_ONLYDIR) as $dir) {
  39. if ($dir == 'tmp-tf/') continue;
  40. echo '<h2>'.$dir.'</h2>';
  41. foreach(glob("$dir*.$type") as $img) {
  42. echo '<a href="'.$img.'" title="'.$img.'" rel="'.$dir.'" class="popup">';
  43. echo '<img src="'.thumbfly( array( 'src' => $img, 'w' => 125, 'h' => 125) ). '" title="'.$img.'" />';
  44. echo '<span>'.str_replace(dirname($img),'',$img).'</span>';
  45. echo '</a>'."\n";
  46. ++$i;
  47. }
  48. }
  49. echo '<p class="clear">' . $i . ' ' . $type . ' match' . ( ($i != '1') ? 'es' : '' ) . '</p>';
  50. }
  51. get_imgs('jpg'); repeat for 'gif' and/or 'png'
  52. ?>
  53. <?php include('tf.php'); /*include ThumbFly function*/ ?>
  54. </div>
  55. </body>
  56. </html>

Report this snippet  

You need to login to post a comment.