cdoggg94 Posted February 22, 2012 Share Posted February 22, 2012 What I want to do is to upload an image, find out what the size is and then make the height=377, and keep with width at the same ratio. this is my upload code: <?php error_reporting(0); mysql_connect("localhost","root","") or die(mysql_error()); mysql_select_db("myDB") or die(mysql_error()); $picture = $_FILES['image']['tmp_name']; $brand = $det['pro_name']; $year = $det['pro_vint']; $story = $det['pro_story']; $description = $det['pro_desc']; $why = $det['pro_why']; $intensity = $det['F12']; $body = $det['F11']; $sweet = $det['F8']; $acid = $det['F9']; $oak = $det['F10']; $lcbo = $det['lcbo_num']; $size = $det['pro_size']; $btl = $det['pro_btl']; $price = $det['pro_price']; $lto = $det['F7']; $audio = $det['wineAudio']; if(!isset($picture)) echo ""; else { $image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); $image_name = addslashes($_FILES['image']['name']); $image_size = getimagesize($_FILES['image']['tmp_name']); list($width, $height, $type, $attr) = getimagesize($_FILES['image']['tmp_name']); if($height != $width * 1.5 ){ echo "Image does not meet requirements"; }else{ if($image_size==FALSE) echo "This is not an Image"; else{ if(!$insert = mysql_query ("UPDATE `phpmy1_vincastweb_com`.`Sheet1` SET `image_name` = '".$image_name."', image='".$image."' WHERE `pro_id` ='".$id."'")) echo "Problem Uploading Image."; else{ $lastid = mysql_insert_id(); echo "Image Uploaded!<p />".$text."<p /><p /> Your Image:<p />"; $lastid = $id; echo "<img src='get_2.php?Product=$lastid' width='250' height='320' /><br />Click <a href='Agency/product3.php?Product=".$id."' target='_blank'>HERE</a> to view with Product" ; } } } } ?> right now I have it so that its at a ratio of height=3, and width=2...everything works fine but its not exactly what i want.. any ideas ? Quote Link to comment https://forums.phpfreaks.com/topic/257562-re-image-resize-on-upload/ Share on other sites More sharing options...
cdoggg94 Posted February 22, 2012 Author Share Posted February 22, 2012 Am I so far off here that no one can even understand what I am trying to do ? lol Quote Link to comment https://forums.phpfreaks.com/topic/257562-re-image-resize-on-upload/#findComment-1320142 Share on other sites More sharing options...
Pikachu2000 Posted February 22, 2012 Share Posted February 22, 2012 It's only been 31 minutes. Quote Link to comment https://forums.phpfreaks.com/topic/257562-re-image-resize-on-upload/#findComment-1320147 Share on other sites More sharing options...
scootstah Posted February 22, 2012 Share Posted February 22, 2012 There's all kinds of snippets and tutorials floating around for this. Here's the first result of a Google: http://snipplr.com/view/753/ Quote Link to comment https://forums.phpfreaks.com/topic/257562-re-image-resize-on-upload/#findComment-1320149 Share on other sites More sharing options...
BigTime Posted February 23, 2012 Share Posted February 23, 2012 Hi cdoggg94 Im working on a similar issue. Here is my working code to get current width height then return desired scaled height, maybe you can work with it. // Constraints $img_path = MY IMG PATH HERE; $max_width = 110; $max_height = 400; list($width, $height) = getimagesize($img_path); $ratioh = $max_height/$height; $ratiow = $max_width/$width; $ratio = min($ratioh, $ratiow); // New dimensions $mywidth = intval($ratio*$width); $myheight = intval($ratio*$height); mywidth and myheight will return your scaled numbers then you can do what you want with them. Quote Link to comment https://forums.phpfreaks.com/topic/257562-re-image-resize-on-upload/#findComment-1320310 Share on other sites More sharing options...
cdoggg94 Posted February 23, 2012 Author Share Posted February 23, 2012 Thank you ! I will try it out right now. What ratio does that give you ? Quote Link to comment https://forums.phpfreaks.com/topic/257562-re-image-resize-on-upload/#findComment-1320407 Share on other sites More sharing options...
cdoggg94 Posted February 23, 2012 Author Share Posted February 23, 2012 I have adapted it to work with my code. $image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); $image_name = addslashes($_FILES['image']['name']); $image_size = getimagesize($_FILES['image']['tmp_name']); //$img_path = $image; $max_width = 250; $max_height = 377; list($width, $height) = $image_size; //echo $width.",".$height; $ratioh = $max_height/$height; $ratiow = $max_width/$width; $ratio = min($ratioh, $ratiow); // New dimensions $mywidth = intval($ratio*$width); $myheight = intval($ratio*$height); //echo $mywidth.",".$myheight; Then I am going to insert $mywidth and $myheight into the table with the rest of the form information and use that as my image height and width when i display them on any given page. Many thanks ! I was getting a little frustrated haha. Quote Link to comment https://forums.phpfreaks.com/topic/257562-re-image-resize-on-upload/#findComment-1320429 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.