Link to home
Create AccountLog in
Avatar of kingsburymedia
kingsburymediaFlag for Canada

asked on

php looping images from directory into jquery slimbox

I'm trying to use php to grab jpgs from a gallery directory, dynamically resize them and spit them out in a loop to be used with slimbox/lightbox. Everything seems to work great in IE but in Firefox it says there are 14 images (this number can vary) in the slideshow but I'm only testing with 3 images. When I go through the slideshow, it goes through all 3 images then repeats the last image until it hits the end of the phantom iterations. Very strange indeed. Any thoughts on what's wrong?

http://users.xplornet.com/~sabstock/gallery.php
gallery.php

<?php

// GRAB IMAGES FROM DIR, LOOP THEM WITH JQUERY TAGS
$path = "images/gallery/";
$dir_handle = @opendir($path) or die("Unable to open folder");

while (false !== ($file = readdir($dir_handle))) {

if($file == "thumbnail.php")
continue;
if($file == ".")
continue;
if($file == "..")
continue;

$caption = "Gallery Name";

echo '<li><a href="images/gallery/'.$file.'" rel="lightbox-2009" title="'.$caption.'"><img src="images/gallery/thumbnail.php?im='.$file.'" alt="'.$file.'" /></li>';

}
closedir($dir_handle);

?>

/////

thumbnail.php

<?php 
// Useage: thumbnail.php?im=image.jpg
// Optional: thumbnail.php?im=image.jpg&amp;maxsize=100

$im      = $_GET['im'];
$maxsize = $_GET['maxsize'];
            
if ($maxsize == '') {
	$maxsize = 100;
}

// The file
$filename = $im;

// Set a maximum height and width
$width  = $maxsize;
$height = $maxsize;

// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width_orig, $height_orig) = getimagesize($filename);

if ($width && ($width_orig < $height_orig)) {
	$width = ($height / $height_orig) * $width_orig;
} else {
	$height = ($width / $width_orig) * $height_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);
$image   = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);

// Output
imagejpeg($image_p);
imagedestroy($image);
imageDestroy($image_p);

?>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of mr_egyptian
mr_egyptian
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Avatar of kingsburymedia

ASKER

It's always something stupid like that haha Thanks for the extra eyes :)
I hadn't looked at your php, but line 20 above should read:
echo '<li><a href="images/gallery/'.$file.'" rel="lightbox-2009" title="'.$caption.'"><img src="images/gallery/thumbnail.php?im='.$file.'" alt="'.$file.'" /></a></li>';

Open in new window