title: Resize image on upload php
body: <p>I have a php script for image upload as below</p>
  
  <pre><code>&lt;?php
  $LibID = $_POST[name];
   define ("MAX_SIZE","10000");
   function getExtension($str) {
           $i = strrpos($str,".");
           if (!$i) { return ""; }
           $l = strlen($str) - $i;
           $ext = substr($str,$i+1,$l);
           return $ext;
   }
   $errors=0;
      $image=$_FILES['image']['name'];
      if ($image)
      {
          $filename = stripslashes($_FILES['image']['name']);
          $extension = getExtension($filename);
          $extension = strtolower($extension);
   if (($extension != "jpg") &amp;&amp; ($extension != "jpeg"))
          {
              echo '&lt;h1&gt;Unknown extension!&lt;/h1&gt;';
              $errors=1;
              exit();
          }
          else
          {
   $size=filesize($_FILES['image']['tmp_name']);
  if ($size &gt; MAX_SIZE*1024)
  {
      echo '&lt;h1&gt;You have exceeded the size limit!&lt;/h1&gt;';
      $errors=1;
      exit();
  }
  $image_name=$LibID.'.'.$extension;
  $newname="uimages/".$image_name;
  $copied = copy($_FILES['image']['tmp_name'], $newname);
  if (!$copied)
  {
      echo '&lt;h1&gt;image upload unsuccessfull!&lt;/h1&gt;';
      $errors=1;
      exit();
  }}}
  ?&gt;
  </code></pre>
  
  <p>which uploads the image file to a folder "uimages" in the root. I have made changes in the html file for the compact display of the image by defining "max-height" and "max-width". But i want to resize the image file on upload. The image file may have a maximum width of 100px and maximum height of 150px. The image proportions must be constrained. That is, the image may be smaller than the above dimensions, but, it should not exceed the limit. How can I make this possible??</p>
  
  <p>Thanks in advance :)</p>
  
  <p>blasteralfred..</p>