doforumda Posted April 9, 2010 Share Posted April 9, 2010 hi i am trying to upload images and resize them to thumbnail size through imagecopyresampled. I allowing four kinds of images gif,jpg,jpeg and png. the problem is imagecopyresampled only works for jpg not for others. my code is below please help me out where i am making mistake <?php include("getExtension.php"); $filename = 'banner.gif'; $ext = getExtension($filename); $ext = strtolower($ext); $jpg = false; $png = false; $gif = false; // Content type if($ext=='jpeg' || $ext == 'jpg') { $jpg = true; header('Content-type: image/jpeg'); } if($ext=='png') { $png = true; header('Content-type: image/png'); } if($ext=='gif') { $gif = true; header('Content-type: image/gif'); } // Get new dimensions list($width, $height) = getimagesize($filename); $new_width = 80; $new_height = 80; // Resample $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); // Output if($jpg==true) { imagejpeg($image_p, $save, 100); } if($png==true) { imagepng($image_p, $save, 100); } if($gif==true) { imagegif($image_p, $save, 100); } ?> above code displays this error The image “http://localhost/imageResizer/image_resizer.php” cannot be displayed, because it contains errors. Link to comment https://forums.phpfreaks.com/topic/198082-need-help-in-imagecopyresampled/ Share on other sites More sharing options...
the182guy Posted April 9, 2010 Share Posted April 9, 2010 Of course your code will only work for jpg images. Look at this line: $image = imagecreatefromjpeg($filename); // can't use this on gif or png! You need to to check the image type, if it's gif use imagecreatefromgif() or if it's a png then use imagecreatefrompng() Link to comment https://forums.phpfreaks.com/topic/198082-need-help-in-imagecopyresampled/#findComment-1039342 Share on other sites More sharing options...
doforumda Posted April 9, 2010 Author Share Posted April 9, 2010 now it is working for jpg and gif but not for png i modify my code and add these if($jpg==true) { $image = imagecreatefromjpeg($filename); } if($png==true) { $image = imagecreatefrompng($filename); } if($gif==true) { $image = imagecreatefromgif($filename); } Link to comment https://forums.phpfreaks.com/topic/198082-need-help-in-imagecopyresampled/#findComment-1039345 Share on other sites More sharing options...
sunwukung Posted April 9, 2010 Share Posted April 9, 2010 No offense, but are the images you're loading png's/gifs etc? Can you provide us with some of the error messages? It might be any number of reasons - file size is too large, image wasn't copied to location x... Link to comment https://forums.phpfreaks.com/topic/198082-need-help-in-imagecopyresampled/#findComment-1039354 Share on other sites More sharing options...
doforumda Posted April 9, 2010 Author Share Posted April 9, 2010 now it just display this http://localhost/imageResizer/image_resizer.php no errors are displayed Link to comment https://forums.phpfreaks.com/topic/198082-need-help-in-imagecopyresampled/#findComment-1039374 Share on other sites More sharing options...
oni-kun Posted April 9, 2010 Share Posted April 9, 2010 now it just display this http://localhost/imageResizer/image_resizer.php no errors are displayed Comment out imagepng/jpg/gif lines including header lines, and add error reporting. It will prevent the image from parsing, and send you an actual error. Obviously you can't see one if there is no domain for text to be displayed. Link to comment https://forums.phpfreaks.com/topic/198082-need-help-in-imagecopyresampled/#findComment-1039379 Share on other sites More sharing options...
litebearer Posted April 9, 2010 Share Posted April 9, 2010 might look here... http://www.nstoia.com/toh/imageresize.php Link to comment https://forums.phpfreaks.com/topic/198082-need-help-in-imagecopyresampled/#findComment-1039380 Share on other sites More sharing options...
doforumda Posted April 9, 2010 Author Share Posted April 9, 2010 where should i add error_reporting and how? Link to comment https://forums.phpfreaks.com/topic/198082-need-help-in-imagecopyresampled/#findComment-1039384 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.