Jump to content

Archived

This topic is now archived and is closed to further replies.

cssmatt

Thumbnail generator

Recommended Posts

I am currently trying to implement a thumbnail generator to my site. I have a few photo galleries which are quite large, so i want to display all these photos as thumbnail, which can be then clicked to show the full size image.

The picture path is stored in a mySQL database, and im trying to loop through this DB to retrieve all the photos for the spcific gallery, then run each ful size photo through a thumbnail generator script, to output a small version.

I have this done, but the script seems tempramental to say the least! Everytime i run the script, some thumbs are display and some appear as broken links. But the pictures are different everytime, so its not like it cant find the pictures, because refreshing it display different combinations of broken img's.

The thumbnail script is straight from php.net


[code]
<?php
// File and new size
//$filename = 'http://www.bradmush.co.uk/21/1.jpg';
$percent = 0.25;

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

// Get new sizes
list($width, $height) = getimagesize($filename);
$newwidth = $width * $percent;
$newheight = $height * $percent;

// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filename);

// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);

// Output
imagejpeg($thumb);
?>
[/code]

and i am using the follwoing code to loop through the pictures:

[code]
<?php
    $sql = "SELECT picture_path FROM loc_pictures WHERE gallery_id = '$_GET[gallery]' LIMIT 25";
    $result = mysql_query($sql);

    echo $num = mysql_num_rows($result) . " pictures found";
    
    $x = 1;
    while ($row = mysql_fetch_array($result))
    {

     echo "<a href = '$row[picture_path]' rel = 'lightbox'>";
     echo "<img src='thumb.php?filename=$row[picture_path]' border = '0' /></a>";
     echo " ";
    
     $x ++;
    }

?>
[/code]

The picture path is saved in the format "../gallery/1/1.jpg" and ive also tried changing this to an absolute path, which doesn work either!!

Plus, to add insult to injury sometimes i get a 403 forbidden error, which im not sure if this is related, but it isnt permanent, and seems to be remidied by refreshing my FTP?!

Any help would be grand!!

Share this post


Link to post
Share on other sites
What about if you right click on the image? does it show the right image and does the link follow to the correct location? if so then all i can think is that the computer is overloading and skipping the odd image as too much data transfer have you tryed limiting it to less images and see if it still happens?

Share this post


Link to post
Share on other sites
Yeah if i "Show Picture" then it displays it fine. Changing the limit does help, because the broken images didnt appear in the first 10 photos. Its only over that amount that problems occur.

Is there no other work around than displaying in blocks of 10? Because the full size images are only 400 x 400 photos?! And there are only 24 or so in each gallery??

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.