Avatar of kingsburymedia
kingsburymedia
Flag 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

PHPJavaScriptWeb Development

Avatar of undefined
Last Comment
mr_egyptian

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
mr_egyptian

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
kingsburymedia

ASKER
It's always something stupid like that haha Thanks for the extra eyes :)
mr_egyptian

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

All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck