sandhya Posted May 25, 2009 Share Posted May 25, 2009 Hi all, I'm trying to create thumbnails of images from database. for this i'm using the following code.I used the same code some where else. It worked. But not here. What's the problem? Here is the code. <? $thumb_dir = "admin/gallery/thumbs/"; $filename = 'admin/gallery/'.$rowgal[gal_photo]; $filename1 = 'admin/gallery/thumbs/'.$rowgal[gal_photo]; $thumb_height = 150; // Content type header('(anti-spam-(anti-spam-content-type:)) image/jpeg'); // Get new sizes list($width, $height) = getimagesize($filename); $ratio = ($height/$width); $newheight = $thumb_height; $newwidth = round($thumb_height/$ratio); // Load $thumb = imagecreatetruecolor($newwidth, $newheight); $source = imagecreatefromjpeg($filename); // Resize imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); // Output //imagejpeg($thumb, $thumb_dir, 100); imagejpeg($thumb, $filename1, 100); ?> I hope somebody can help me. Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/159552-problem-with-creating-thumbnail-images-using-php/ Share on other sites More sharing options...
phpdragon Posted May 25, 2009 Share Posted May 25, 2009 I resize like this // create thumbnail (150x150) $file = $_FILES['image_file']['tmp_name']; list($width, $height) = getimagesize($file); if ($width >= $height) { // scale to width $thumb_width = 150; $thumb_height = $height * ($thumb_width / $width); } else { // scale to height $thumb_height = 150; $thumb_width = $width * ($thumb_height / $height); } $image = imagecreatefromjpeg($file); // create thumbnail file $thumb_image = imagecreatetruecolor($thumb_width, $thumb_height); imagecopyresampled($thumb_image, $image, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height); $output_file = "admin/gallery/thumbs/".$_FILES['image_file']['name']; imagejpeg($thumb_image, $output_file, 100); hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/159552-problem-with-creating-thumbnail-images-using-php/#findComment-841742 Share on other sites More sharing options...
sandhya Posted May 26, 2009 Author Share Posted May 26, 2009 Thanks for your code. It works with the images taken from the form. But i am taking the existed images from the database. How can i create thumb nails for those images? Quote Link to comment https://forums.phpfreaks.com/topic/159552-problem-with-creating-thumbnail-images-using-php/#findComment-842171 Share on other sites More sharing options...
phpdragon Posted May 27, 2009 Share Posted May 27, 2009 make your database query for the image names first, then nominate the $file image in a while loop calling the image to be thumb-nailed from its directory Quote Link to comment https://forums.phpfreaks.com/topic/159552-problem-with-creating-thumbnail-images-using-php/#findComment-843030 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.