blah19 Posted December 21, 2008 Share Posted December 21, 2008 Hey! I am working on a script(I'm fairly new, and self taught so it may seem sloppy or inefficient) listed below. In a nutshell, this script creates thumbnails and links them to the larger files. This is just the shell and I plan to expand it a lot, but my main concern is right now my script creates the thumbnail whether it exists or not. I've done some looking around but I can't figure out how to make this script ONLY create a thumbnail if the thumbnail file does not exist already. Any Ideas? function thumbIt($filename,$percent,$prename,$setWidth,$setHeight) { $newdir='slideImages/thumbs/';//Dircetory to store new pic //$prename='t_';//name for creating thumbnails $thumbQ=80;//Quality for saving pic $filenameT=$filename; $filename='slideImages/'.$filename; //====================== //Debugging Hard Vars //$filename='lime.jpg'; //$percent=.3; //====================== // Content type //header('Content-type: image/jpeg'); // Get new sizes list($width, $height) = getimagesize($filename); if($percent!=0) { $newwidth = $width * $percent; $newheight = $height * $percent; } else { $newwidth = $setWidth; $newheight = $setHeight; } // Load $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($filename); // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //Save Image $thumbPath=$newdir.$prename.$filenameT; //consolidate for output imagejpeg($thumb, $thumbPath); // Output //echo($thumbPath); return($thumbPath); } basically I pull all the files from a folder and put them into an array, from the array I send them to HTML via echo. I'll post the entire page it you need it. Quote Link to comment https://forums.phpfreaks.com/topic/137868-quick-question-on-a-script-im-making/ Share on other sites More sharing options...
carrotcake1029 Posted December 21, 2008 Share Posted December 21, 2008 Do you not get a warning when you execute code like this when the file doesn't exist? list($width, $height) = getimagesize($filename); Quote Link to comment https://forums.phpfreaks.com/topic/137868-quick-question-on-a-script-im-making/#findComment-720545 Share on other sites More sharing options...
blah19 Posted December 21, 2008 Author Share Posted December 21, 2008 I do, but as long as there is only images in the file it will always yield an image. Quote Link to comment https://forums.phpfreaks.com/topic/137868-quick-question-on-a-script-im-making/#findComment-720547 Share on other sites More sharing options...
DeanWhitehouse Posted December 21, 2008 Share Posted December 21, 2008 http://uk.php.net/file_exists Quote Link to comment https://forums.phpfreaks.com/topic/137868-quick-question-on-a-script-im-making/#findComment-720549 Share on other sites More sharing options...
carrotcake1029 Posted December 21, 2008 Share Posted December 21, 2008 Could you try something like this then? if (@getimagesize($filename) < 1) //Generate the thumbnail else //Don't generate it as it already exists Quote Link to comment https://forums.phpfreaks.com/topic/137868-quick-question-on-a-script-im-making/#findComment-720552 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.