[Tutorial] How to detect images automatically with Supersized
in Using jQuery Plugins
•
3 months ago
Hi jQuery members :)
I came across this wonderful plugin called Supersized the other day, and I absolutely loved it to bits, except for one small thing - it couldn't detect images in a folder automatically.
With the help of the creator, I've managed to write a small block of PHP that allows the plugin to detect the images automatically, and I though I'd share it!
Firstly open up your demo.html, copy all of the code. Make a file called demo.php or index.php (that bit doesn't really matter). Open your newly create PHP file, and paste all of the copied code in and then save it.
Scroll down to line 56, and you should see this:
The bit we're interested in is the line called 'slides'.
Remove everything within the { } brackets, including the brackets.
Next, paste in this bit of PHP code in place of the brackets:
You can add in the other details, such as URL and Thumb, however they are not necessary for it to work.
Save your PHP file, upload it to your server, and then test it!
I came across this wonderful plugin called Supersized the other day, and I absolutely loved it to bits, except for one small thing - it couldn't detect images in a folder automatically.
With the help of the creator, I've managed to write a small block of PHP that allows the plugin to detect the images automatically, and I though I'd share it!
Firstly open up your demo.html, copy all of the code. Make a file called demo.php or index.php (that bit doesn't really matter). Open your newly create PHP file, and paste all of the copied code in and then save it.
Scroll down to line 56, and you should see this:
- // Components
slide_links : 'blank', // Individual links for each slide (Options: false, 'num', 'name', 'blank')
thumb_links : 1, // Individual thumb links for each slide
thumbnail_navigation : 0, // Thumbnail navigation
slides : [ // Slideshow Images
{image : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/slides/kazvan-1.jpg', title : 'Image Credit: Maria Kazvan', thumb : 'http://buildinternet.s3.amazonaws.com/projects/supersized/3.2/thumbs/kazvan-1.jpg', url : 'http://www.nonsensesociety.com/2011/04/maria-kazvan/'},
The bit we're interested in is the line called 'slides'.
Remove everything within the { } brackets, including the brackets.
Next, paste in this bit of PHP code in place of the brackets:
- <?php
//path to directory to scan
$directory = "imgDir/";
//get all image files with a .jpg extension.
$images = glob($directory . "*.jpg");
//print each file name
foreach($images as $image)
{
echo "{image : 'http://urlHere.com/" . $image . "', title : '" .$image . "'},";
}
?>
You can add in the other details, such as URL and Thumb, however they are not necessary for it to work.
Save your PHP file, upload it to your server, and then test it!
2



