title: How to resize image before upload
body: <p>I am trying to resize images before upload.  I added the line <code>$img = resize_image($_FILES['Image']['tmp_name'], 200, 200);</code> to the code below.  The code is working properly to upload.  Now I am just trying to adjust the size of the image.  I am not sure how to take the return value $img and save it with the move_uploaded_file.  When I try and replace <code>$_FILES['Image']['tmp_name]</code> with <code>$img</code>, I get a parse error.  I also added the <code>resize_image</code> function so you can see what it is exactly returning.</p>
  
  <pre><code>    {
              $image_name= $_FILES['Image']['name'];
              $img = resize_image($_FILES['Image']['tmp_name'], 200, 200);
          $image_name =  $picCounter .$firstName .$image_name;
          move_uploaded_file( $_FILES['Image']['tmp_name'], "IMG/$image_name");
          correctImageOrientation("IMG/$image_name");
  
          $image_path = "/IMG/" .$image_name;
  
          $picCounter = $picCounter++;
          $sql = ("UPDATE LoginInformation SET PicCounter = PicCounter + 1 WHERE Email = '" . $useremail . "'" );
          mysqli_query($conn, $sql);
      }
      else
      {
          $image_path = "/IMG/square-image.png";
      }
  </code></pre>
  
  <p>here is the resize function</p>
  
  <pre><code>function resize_image($file, $w, $h, $crop=FALSE) {
      list($width, $height) = getimagesize($file);
      $r = $width / $height;
      if ($crop) {
          if ($width &gt; $height) {
              $width = ceil($width-($width*abs($r-$w/$h)));
          } else {
              $height = ceil($height-($height*abs($r-$w/$h)));
          }
          $newwidth = $w;
          $newheight = $h;
      } else {
          if ($w/$h &gt; $r) {
              $newwidth = $h*$r;
              $newheight = $h;
          } else {
              $newheight = $w/$r;
              $newwidth = $w;
          }
      }
      $src = imagecreatefromjpeg($file);
      $dst = imagecreatetruecolor($newwidth, $newheight);
      imagecopyresampled($dst, $src, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  
      return $dst;
  }
  </code></pre>