mdvignesh Posted February 6, 2012 Share Posted February 6, 2012 Help me I am getting Notice: Undefined index: extension Quote Link to comment https://forums.phpfreaks.com/topic/256521-image-file-extension-in-thumbnail/ Share on other sites More sharing options...
spiderwell Posted February 6, 2012 Share Posted February 6, 2012 please post the relevant code so we can at least have an idea where to start Quote Link to comment https://forums.phpfreaks.com/topic/256521-image-file-extension-in-thumbnail/#findComment-1315039 Share on other sites More sharing options...
mdvignesh Posted February 7, 2012 Author Share Posted February 7, 2012 <?php function generateThumbs() { $pathToScreens = "D:/wamp/www/vignesh_2/up_images/"; // Directory to your images you want converted to thumbnails. $pathToThumbs = "D:/wamp/www/vignesh_2/up_images/thumb/"; // Directory to your thumbnails. $thumbWidth = 70; // Width of the thumbnails generated. $dir = opendir($pathToScreens) or die("Could not open directory"); $counter = 0; while(($fname = readdir($dir)) !== false) { if($fname != "." && $fname != "..") { // Remove folders. $valid_extensions = array("jpg","jpeg","gif","png"); // Only jpeg images allowed. $info = pathinfo($pathToScreens . $fname); // print_r($info); if( in_array (strtolower ($info["extension"]),$valid_extensions)) { // Make sure the file is an image file by checking its extension to the array of image extensions. $img = imagecreatefromjpeg($pathToScreens . $fname); // Select the file as an image from the directory. $width = imagesx($img); $height = imagesy($img); // Collect its width and height. $newHeight = floor($height * ($thumbWidth / $width)); // Calculate new height for thumbnail. $tempImage = imagecreatetruecolor($thumbWidth,$newHeight); // Create a temporary image of the thumbnail. // Copy and resize old image into new image. imagecopyresized($tempImage,$img, 0, 0, 0, 0, $thumbWidth,$newHeight,$width,$height); $genThumb = imagejpeg($tempImage,$pathToThumbs . $fname); // Create the thumbnail with the new width and height in the thumbnails directory. // I added a rand 3 digit number in front of the file name to avoid overwrite. $counter++; // Increment. } } } if($counter > 0) { return $counter . " thumbnails generated from the directory \"".$pathToScreens."\"."; } else { return "No image files could be processed."; } closedir($dir); // Close the directory. } //echo "<img src='up_images/thumb/650Blue hills.jpg' />"; ?> 17526_.php Quote Link to comment https://forums.phpfreaks.com/topic/256521-image-file-extension-in-thumbnail/#findComment-1315354 Share on other sites More sharing options...
Deoctor Posted February 7, 2012 Share Posted February 7, 2012 Works fine for me. Try to give something as error_reporting(off); before code starts. Quote Link to comment https://forums.phpfreaks.com/topic/256521-image-file-extension-in-thumbnail/#findComment-1315356 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.