shage Posted December 28, 2007 Share Posted December 28, 2007 function createThumbs( $pathToImages, $pathToThumbs) { $dir = opendir( $pathToImages ); echo "<b>Creating Thumbnails</b> <br />"; while (false !== ($fname = readdir( $dir ))) { $info = pathinfo($pathToImages . $fname); if ( strtolower($info['extension']) == 'jpg' ) { echo "Creating thumbnail for <b>{$fname}</b> <br />"; $width = 150; $height = 150; $dimensions = getimagesize("{$fname}"); $canvas = imagecreatetruecolor($width,$height); $piece = imagecreatefromjpeg("{$fname}"); $newwidth = $dimensions[0] / 2; $newheight = $dimensions[1] / 2; $cropLeft = ($newwidth/2) - ($width/2); $cropHeight = ($newheight/2) - ($height/2); imagecopyresized($canvas, $piece, 0,0, $cropLeft, $cropHeight, $width, $height, $newwidth, $newheight); unset($piece); if (imagejpeg($canvas,"{$pathToThumbs}{$fname}",90)) { echo 'Image crop successful<br />'; } else { echo 'Image crop failed<br />'; } } } unset($piece); closedir( $dir ); } createThumbs("imagecreation/","imagecreation/images/thumbnails/"); when script runs it outputs Creating thumbnail for Vicky07.jpg Warning: getimagesize(Vicky07.jpg) [function.getimagesize]: failed to open stream: No such file or directory file is there, chmod is right, and hell its getting the filename so it must be a real file or directory Quote Link to comment https://forums.phpfreaks.com/topic/83508-solved-help-with-function/ Share on other sites More sharing options...
GingerRobot Posted December 28, 2007 Share Posted December 28, 2007 As far as i can see $fname should be undefined. Yet, from the output you get, it is, evidently, defined. Are you sure this is the script you are running? Quote Link to comment https://forums.phpfreaks.com/topic/83508-solved-help-with-function/#findComment-424861 Share on other sites More sharing options...
shage Posted December 28, 2007 Author Share Posted December 28, 2007 prob in code above let me copy it Quote Link to comment https://forums.phpfreaks.com/topic/83508-solved-help-with-function/#findComment-424863 Share on other sites More sharing options...
shage Posted December 28, 2007 Author Share Posted December 28, 2007 idea was to open folder and make thumbs from it, since i unload my camera weekly and cropping thumbs by hand sucks, esp now that i have a million christmas pics to upload Quote Link to comment https://forums.phpfreaks.com/topic/83508-solved-help-with-function/#findComment-424866 Share on other sites More sharing options...
kenrbnsn Posted December 28, 2007 Share Posted December 28, 2007 You need to specify the path to the file, not just the file: <?php function createThumbs( $pathToImages, $pathToThumbs) { $dir = opendir( $pathToImages ); echo "<b>Creating Thumbnails</b> <br />"; while (false !== ($fname = readdir( $dir ))) { $info = pathinfo($pathToImages . $fname); if ( strtolower($info['extension']) == 'jpg' ) { echo "Creating thumbnail for <b>{$fname}</b> <br />"; $width = 150; $height = 150; $dimensions = getimagesize($pathToImages . $fname); $canvas = imagecreatetruecolor($width,$height); $piece = imagecreatefromjpeg($pathToImages . $fname); $newwidth = $dimensions[0] / 2; $newheight = $dimensions[1] / 2; $cropLeft = ($newwidth/2) - ($width/2); $cropHeight = ($newheight/2) - ($height/2); imagecopyresized($canvas, $piece, 0,0, $cropLeft, $cropHeight, $width, $height, $newwidth, $newheight); unset($piece); if (imagejpeg($canvas, $pathToThumbs . $fname,90)) { echo 'Image crop successful<br />'; } else { echo 'Image crop failed<br />'; } } } unset($piece); closedir( $dir ); } createThumbs("imagecreation/","imagecreation/images/thumbnails/"); ?> Since you're doing this for pictures uploaded from a camera, you might want to check to see if the original images have thumbnails stored with them. Take a look at the exif_thumbnail() function. Ken Quote Link to comment https://forums.phpfreaks.com/topic/83508-solved-help-with-function/#findComment-424872 Share on other sites More sharing options...
shage Posted December 28, 2007 Author Share Posted December 28, 2007 thank you thank you Quote Link to comment https://forums.phpfreaks.com/topic/83508-solved-help-with-function/#findComment-424876 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.