Slideshow

jQuery Carousel - Images From Folder

on Tuesday, 11 October 2011. Posted in Slideshow, All

Get the source code
$1.99

Includes working source code with images, style sheet and javascript.

One of my favorite free jquery slideshow scripts is Jquery Carousel Lite

The major problem I had with the script is everytime I wanted to add another picture to the slideshow, I had to modify the jquery code to include that image. I wrote a script that will do the following:


1) Automatically lists the image files inside a directory and load them into your jquery carousel.


2) Reads the picture metadata and adds it to the jquery carousel script


  • Metadata: Title becomes the Image Alt Tag
  • Metadata: Subject becomes the Image Link URL
  • Metadata: Comments becomes the Caption

demo


carouselexample.php
//----------------------------------------------------
// jQuery Carousel Enhancement
// Created by Jaz Witham (Jazzerup)
// 2011
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
// Script reads the image files and 
// image metadata into the jQuery Carousel Script
//----------------------------------------------------
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script> 
<script src="js/jcarousellite_1.js" type="text/javascript"></script>
</head>
<body>
<!-- Carousel -->
<div id="carousel"> <a href="#" title="Previous" class="prev">Previous</a> <a href="#" title="Next" class="next">Next</a>
  <div style="visibility: visible; overflow: hidden; position: relative; z-index: 2; left: 0px; width: 864px;" class="content">
    <ul style="margin: 0pt; padding: 0pt; position: relative; list-style-type: none; z-index: 1; width: 2592px; left: -864px;">
 
<?php 
//Relative path to yout image directory
$dirpath = "../slideshow";
//Website URL to that same image directory
$dirURL = "http://www.jazzerup.com/blogexamples/slideshow/";
 
$folder = opendir($dirpath);
$pic_types = array("jpg", "jpeg");
$alttag = ""; 
$websiteurl= ""; 
$caption = ""; 
$index = array();
 
//Loop through the images in the directory
while ($file = readdir ($folder)) {
  if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$pic_types))
      {                       
      $items[] = $file;            
    }
}
//each time it loads it shuffles the images
shuffle($items);
for($i=0; $i<sizeof($items); $i++) {
  $picpath = $dirpath . "/" . $items[$i];
  $exif = exif_read_data($picpath, 'EXIF');
  $alttag = $exif['Title']; //alt tag
  $websiteurl= $exif['Subject']; //website url
  $caption = $exif['Comments']; //caption
 
  $varimages = $varimages . "<li style='overflow: hidden; float: left; width: 216px; height: 136px;'>";
 
//Build the html code based on the metadata 
  $varimages =  $varimages . " <img src='$picpath' height='120' width='200' style='border:3px solid #FFF;' alt='$alttag' />" . "\n\n" ;
 
  $alttag = ""; 
  $websiteurl= ""; 
  $caption = "";
  $varimages =  $varimages . "</li>";
 }
closedir($folder);
 
echo $varimages;
?>
    </ul>
  </div>
</div>
<!-- [END] Carousel --> 
<script type="text/javascript">
    $(window).load(function() {
 
      $("#carousel .content").jCarouselLite({
          btnNext: ".next",
          btnPrev: ".prev",
          speed: 800,
          visible: 4
      });
 
 
    });
    </script>
</body>
 

jQuery Slider - Images From Folder

on Monday, 24 October 2011. Posted in Slideshow, All

Get the source code
$1.99

Includes working source code with images, style sheet and javascript.

One of my favorite free jquery slideshow scripts is Jquery Looped Slider

The major problem I had with the script is everytime I wanted to add another picture to the slideshow, I had to modify the jquery code to include that image. I wrote a script that will do the following:


1) Automatically lists the image files inside a directory and load them into your jquery carousel.


2) Reads the picture metadata and adds it to the jquery carousel script


  • Metadata: Title becomes the Image Alt Tag
  • Metadata: Subject becomes the Image Link URL
  • Metadata: Comments becomes the Caption

demo

loopedslider_example.php
//----------------------------------------------------
// Looped Slider Example
// Created by Jaz Witham (Jazzerup)
// 2011
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
// Script reads the image files and 
// image metadata into a looped jquery gallery script
//----------------------------------------------------
<div id="header">
<div id="slider">  
  <div class="container">
    <ul class="slides">
         <?php 
//Relative path to yout image directory
$dirpath = "slideshow";
//Website URL to that same image directory
$dirURL = "http://www.jazzerup.com/blogexamples/loopedslider/slideshow/";
 
$folder = opendir($dirpath);
$pic_types = array("jpg", "jpeg");
$alttag = ""; 
$websiteurl= ""; 
$caption = ""; 
$index = array();
 
//Loop through the images in the directory
while ($file = readdir ($folder)) {
  if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$pic_types))
      {                       
      $items[] = $file;            
    }
}
//each time it loads it shuffles the images
shuffle($items);
for($i=0; $i<sizeof($items); $i++) {
  $picpath = $dirpath . "/" . $items[$i];
  $exif = exif_read_data($picpath, 'EXIF');
  $alttag = $exif['Title']; //alt tag
  $websiteurl= $exif['Subject']; //website url
  $caption = $exif['Comments']; //caption
    $title = $exif['Title']; //title
  $comments = $exif['Comments']; //comments
 
 $varimages = $varimages . "<li><div class='thumbholder'>";
 
 
//Build the html code based on the metadata 
  if ($caption != "") {
    $caption =  "title='" . $caption  . "'";
    $alt = "alt='" . $caption  . "'";
  }
  if ($alttag != "") {
    $alt =  "alt='" . $alttag . "'";
  }
  if ($websiteurl != "") {
    $varimages =  $varimages . " <a href='$websiteurl'><img src='$picpath' $alt $caption width='625' height='254' /></a>" ;
  } else {
  $varimages =  $varimages . " <img src='$picpath' $alt $caption width='625' height='254'  />";
      }
  $alttag = ""; 
  $websiteurl= ""; 
  $caption = ""; 
  $varimages =  $varimages . "</div><div class='txtholder'>
            <h2>$title</h2>
          <p>$comments </p></div></li>";
}
closedir($folder);
 
echo $varimages;
?>
 
 
    </ul>
  </div>
  <ul class="pagination">
 <?php   
 for($i=0; $i<sizeof($items); $i++) {
  echo "<li><a href='#'>$i</a></li>";
 }
    ?>
    </ul>  
  </div>
</div>
</div>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" ></script>
<script src="js/loopedslider.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
$(document).ready(function(){     
    $('#slider').loopedSlider({
      autoStart: 8000,
      restart: 0,
      slidespeed: 2000,
      fadespeed: 800
    });  
});
</script>
 
 

jQuery Nivo Slider - Images From Folder

on Sunday, 02 October 2011. Posted in Slideshow, All

Get the source code
$1.99

Includes working source code with images, style sheet and javascript.

One of my favorite free jQuery slideshow scripts is Nivo Slider

The major problem I had with the script is everytime I wanted to add another picture to the slideshow, I had to modify the jquery code to include that image. I wrote a script that will do the following:


1) Automatically lists the image files inside a directory and load them into your nivo slider.


2) Reads the picture metadata and adds it to the Nivo script


  • Metadata: Title becomes the Nivo Image Alt Tag
  • Metadata: Subject becomes the Nivo Image Link URL
  • Metadata: Comments becomes the Nivo Caption

demo

nivoexample.php
<!--
//----------------------------------------------------
// Nivo Slider Enhancement
// Created by Jaz Witham (Jazzerup)
// 2011
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND
// Script reads the image files and 
// image metadata into the nivo slider script
//----------------------------------------------------
-->
<body>
<div id="wrapper"> 
  <div class="slider-wrapper theme-default">
    <div class="ribbon"></div>
    <div id="slider" class="nivoSlider">
<?php 
//This php code will generate your list of images based on 
//image files in a folder
 
$dirpath = "slideshow";
$dirURL = "http://www.jazzerup.com/blogexamples/slideshow/";
$folder = opendir($dirpath); // Use 'opendir(".")' if the PHP file is in the same folder as your images. Or set a relative path 'opendir("../path/to/folder")'.
$pic_types = array("jpg", "jpeg", "gif", "png");
$alttag = ""; //caption
$websiteurl= ""; //alt tag
$caption = ""; //website url
 
$index = array();
while ($file = readdir ($folder)) {
  if(in_array(substr(strtolower($file), strrpos($file,".") + 1),$pic_types))
      {                       
      $items[] = $file;                                  
      }
}
for($i=0; $i<sizeof($items); $i++) {                  
  $picpath = $dirpath . "/" . $items[$i];
 
  //Get the meta data
  $exif = exif_read_data($picpath, 'EXIF');
  $alttag = $exif['Title']; //alt tag
  $websiteurl= $exif['Subject']; //website url
  $caption = $exif['Comments']; //caption
  if ($caption != "") {
    $caption =  "title='" . $caption  . "'";
    $alt = "alt='" . $caption  . "'";
  }
  if ($alttag != "") {
    $alt =  "alt='" . $alttag . "'";
  }
  if ($websiteurl != "") {
    $varimages =  $varimages . " <a href='$websiteurl'><img src='$picpath' $alt $caption /></a>" . "\n\n" ;
  } else {
  $varimages =  $varimages . " <img src='$picpath' $alt $caption />" . "\n\n" ;
      }
  $alttag = ""; //caption
  $websiteurl= ""; //alt tag
  $caption = ""; //website url
}
closedir($folder);
$varimages = substr_replace($varimages ,"",-1);
echo $varimages;
?>
    </div>
  </div>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.nivo.slider.pack.js"></script> 
<script type="text/javascript">
    $(window).load(function() {
        $('#slider').nivoSlider();
    });
    </script>
</body>
 
 
 

 

Updating Metadata in a file is very easy. On windows:

  1. Right click on the file
  2. Select Properties
  3. Select the "Details" tab
  4. Update Title, Subject and Comments and press "Okay"