Jump to content

I give up!?? Please help.


sodascape

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");
?>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.