SkyRanger Posted June 10, 2012 Share Posted June 10, 2012 Hey all, Ok, here is what I need to do, I already have it to create a thumb, but I also need to condense the uploaded image down 50%. Anybody have any idea, this is what I have so far: if(isset($_POST['submit'])) { $path_thumbs = "thumbs/"; $path_big = "images/"; $img_thumb_width = 100; $extlimit = "yes"; //Limit allowed extensions? (no for all extensions allowed) $limitedext = array(".gif",".jpg",".png",".jpeg",".bmp"); $file_type = $_FILES['vImage']['type']; $file_name = $_FILES['vImage']['name']; $file_size = $_FILES['vImage']['size']; $file_tmp = $_FILES['vImage']['tmp_name']; if(!is_uploaded_file($file_tmp)){ echo "Error: Please select a file to upload!. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); //exit the script and don't process the rest of it! } //check the file's extension $ext = strrchr($file_name,'.'); $ext = strtolower($ext); if (($extlimit == "yes") && (!in_array($ext,$limitedext))) { echo "Wrong file extension. <br>--<a href=\"$_SERVER[php_SELF]\">back</a>"; exit(); } //so, whats the file's extension? $getExt = explode ('.', $file_name); $file_ext = $getExt[count($getExt)-1]; $rand_name = $file_name; //the new width variable $ThumbWidth = $img_thumb_width; ////////////////////////// // CREATE THE THUMBNAIL // ////////////////////////// //keep image type if($file_size){ if($file_type == "image/pjpeg" || $file_type == "image/jpeg"){ $new_img = imagecreatefromjpeg($file_tmp); }elseif($file_type == "image/x-png" || $file_type == "image/png"){ $new_img = imagecreatefrompng($file_tmp); }elseif($file_type == "image/gif"){ $new_img = imagecreatefromgif($file_tmp); } //list the width and height and keep the height ratio. list($width, $height) = getimagesize($file_tmp); //calculate the image ratio $imgratio=$width/$height; if ($imgratio>1){ $newwidth = $ThumbWidth; $newheight = $ThumbWidth/$imgratio; }else{ $newheight = $ThumbWidth; $newwidth = $ThumbWidth*$imgratio; } //function for resize image. if (function_exists(imagecreatetruecolor)){ $resized_img = imagecreatetruecolor($newwidth,$newheight); }else{ die("Error: Please make sure you have GD library ver 2+"); } //the resizing is going on here! imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); //finally, save the image ImageJpeg ($resized_img,"$path_thumbs/ies_thumb-$cid-$rand_name"); ImageDestroy ($resized_img); ImageDestroy ($new_img); } move_uploaded_file ($file_tmp, "$path_big/ies-$cid-$rand_name"); I am probably looking at it right now and not even seeing it. Quote Link to comment https://forums.phpfreaks.com/topic/263929-resize-image/ Share on other sites More sharing options...
Pikachu2000 Posted June 10, 2012 Share Posted June 10, 2012 You haven't really told us what problem you're having. Quote Link to comment https://forums.phpfreaks.com/topic/263929-resize-image/#findComment-1352561 Share on other sites More sharing options...
SkyRanger Posted June 10, 2012 Author Share Posted June 10, 2012 Sorry, the problem I am having is taking the original file that is being uploaded and reduce the size by 50%. I can do it with the thumb, but not sure if I can still do it with the original. Quote Link to comment https://forums.phpfreaks.com/topic/263929-resize-image/#findComment-1352563 Share on other sites More sharing options...
Pikachu2000 Posted June 10, 2012 Share Posted June 10, 2012 OK, and what part of that is giving problems? Is there a specific error or something that's failing? Quote Link to comment https://forums.phpfreaks.com/topic/263929-resize-image/#findComment-1352565 Share on other sites More sharing options...
SkyRanger Posted June 10, 2012 Author Share Posted June 10, 2012 the problem I am running into is having the same image resize twice, not sure how to exactly do that I was thinking of using imagecreatefrom but is there a simpler way of doing this instead of making one for each type of image. ie jpg png gif etc... with the code I am currently using. So what I am trying to figure out what do is: upload image.ext resize orig image.ext to 60% then create thumbimage.ext to 100px x 100px all in the same code Quote Link to comment https://forums.phpfreaks.com/topic/263929-resize-image/#findComment-1352570 Share on other sites More sharing options...
SkyRanger Posted June 10, 2012 Author Share Posted June 10, 2012 ok, scrapped the script, did another google search and found what I was looking for. Quote Link to comment https://forums.phpfreaks.com/topic/263929-resize-image/#findComment-1352571 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.