SieRobin Posted July 12, 2006 Share Posted July 12, 2006 Ok so I have it set so your user image you chose to upload, it resizes in the forum, just so it isn't huge and makes the forum look goofy.. yet I've come across a problem I can not fix. The script resizes all JPEG images, but it won't resize PNG or GIF, which are the other extensions I'm allowing. Can someone tell me if I have a flaw in my script, because I'm just confused?[code]<?phpsession_start();if (isset($_GET['img'])) {$img_name = $_GET['img'];$file_type=$_FILES['image']['type'];$max_width=120;$max_height=120;$size=getimagesize($img_name);$width_ratio=($size[0] / $max_width);$height_ratio =($size[1] / $max_height);if($width_ratio>=$height_ratio) { $ratio=$width_ratio;}else{ $ratio=$height_ratio;}$new_width=($size[0] / $ratio);$new_height=($size[1] / $ratio);header("Content-Type: image/jpeg, image/gif, image/png");if ($file_type="image/pjpeg"||$file_type="image/jpeg") {$src_img = imagecreatefromjpeg($img_name); }elseif ($file_type="image/x-png"||$file_type="image/png") {$src_img = imagecreatefrompng($img_name); }elseif ($file_type="image/gif") {$src_img = imagecreatefromgif($img_name); }$thumb = imagecreatetruecolor($new_width,$new_height);imagecopyresampled($thumb, $src_img, 0,0,0,0,($new_width),($new_height),$size[0],$size[1]);imagejpeg($thumb);imagedestroy($src_img);imagedestroy($thumb);exit();}?>[/code]Like I said, it resizes JPEGs just fine, and they're good to go, but the others won't work. Quote Link to comment https://forums.phpfreaks.com/topic/14402-image-resize/ Share on other sites More sharing options...
SieRobin Posted July 12, 2006 Author Share Posted July 12, 2006 Wait I don't think the file_type is working, hmmn. Quote Link to comment https://forums.phpfreaks.com/topic/14402-image-resize/#findComment-56919 Share on other sites More sharing options...
SieRobin Posted July 12, 2006 Author Share Posted July 12, 2006 Well I figured out that I can't use $_FILES because I'm not taking it from a form or input.. therefore I can't take the type from the image.. any other ideas on how I can tell what the file type is? Quote Link to comment https://forums.phpfreaks.com/topic/14402-image-resize/#findComment-56936 Share on other sites More sharing options...
SieRobin Posted July 12, 2006 Author Share Posted July 12, 2006 Got it, nevermind. Quote Link to comment https://forums.phpfreaks.com/topic/14402-image-resize/#findComment-56944 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.