Jump to content

Archived

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

sodascape

I give up!?? Please help.

Recommended Posts

I dont know where else to turn.... this script is supposed to read all of the images in a directory, determine if the directory has a thumbnail folder, if not, it is supposed to create one and create thumbs for all of those images and then display the images in a table until there are no more left.  THe script is short, but I keep getting error messages.

Warning: imagecreatetruecolor(): Invalid image dimensions in /home/christop/public_html/illustrations/read_dir.php on line 22

Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/christop/public_html/illustrations/read_dir.php on line 23

Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/christop/public_html/illustrations/read_dir.php on line 24
./bub.jpg

Please help.

---------------------------- The Script I have so far...................................................
<?php
// //////////////////////////////////////////////////////////////////////////////////////////////////////////
function add_folder_to_directory_path($path,$foldertoadd) {
$base_dir = substr($path,0,strrpos($path,"/")).$foldertoadd; //take path apart, add new folder to it.
// OLD $base_dir = substr($path,0,strrpos($path,"/")).'/'.$foldertoadd; //take path apart, add new folder to it.
$newpath = $base_dir . strrchr($path,"/"); // add the file name back on.
return $newpath;
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////
function createThumbnail($image)
{
$thumbnail_path = add_folder_to_directory_path($item,"thumbs");

copy($image,$thumbnail_path);
$srcImg = imagecreatefromjpeg("$image");
$origWidth = imagesx($srcImg);
$origHeight = imagesy($srcImg);

$ratio = $thumbWidth / $origWidth;
$thumbHeight = $origHeight * $ratio;

$thumbImg = imagecreatetruecolor($thumbWidth, $thumbHeight);
imagecopyresampled($thumbImg, $srcImg, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $origWidth, $origHeight);
imagejpeg($thumbImg, "$thumbDirectory/$imageName");
}
// //////////////////////////////////////////////////////////////////////////////////////////////////////////
?>

<?php
// READ DIRECTORY, CHECK JPG EXTENTION, PUT IMAGES INTO ARRAY
$path = './';
if ($handle = opendir($path)) {  // get all the images in there and make a pic order.
    while (false !== ($file = readdir($handle))) {
        if ($file != '.' && $file != '..' && eregi(".jpg",$file)) {
// $allpics[] = $file; // simply list all the pics in an array (without extension) for later saving
$allpics[] = $path.$file;
}
    }
    closedir($handle);
}

foreach ($allpics as $item) {
$thumbnail_path = add_folder_to_directory_path($item,"thumbs");

if (!is_file($thumbnail_path)) {
// if there is no file in the thumbs directory
createThumbnail($item); // CREATE FUNCTION
// ADD TABLE COUNTER
}
echo $item;

// ADDING NEW THUMBS FOLDER TO DIRECTORY
$newfolder = add_folder_to_directory_path($oldfolder, "thumbs");
?>

Share this post


Link to post
Share on other sites
I figured that would be determined by each file that is in the directory when the script reads them.

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.