Jump to content


Photo

I give up!?? Please help.


  • Please log in to reply
2 replies to this topic

#1 sodascape

sodascape
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 22 July 2006 - 09:12 AM

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");
?>

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 22 July 2006 - 12:40 PM

You havn't defined $thumbWidth

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 sodascape

sodascape
  • Members
  • PipPip
  • Member
  • 20 posts

Posted 22 July 2006 - 06:04 PM

I figured that would be determined by each file that is in the directory when the script reads them.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users