title: Resizing Image (create thumbnail) on ftp_put
body: <p>So I have a simple goal but I can't seem to get the one part to work.</p>
  
  <p>1) Upload an image and create 3 different sizes: LG, MD, SM; then rename images.</p>
  
  <p>2) Move the images from server/website A to server/website B.</p>
  
  <p>I have the uploading and renaming working for all three images, but I can't figure out what I'm doing wrong with the re-sizing part. Any help would be greatly appreciated. </p>
  
  <p>Note: I am currently trying to just get one image to resize, I figured one at a time would be smartest to make sure I understand what is happening.</p>
  
  <p>Code:</p>
  
  <pre><code>function thumb_resize_image_new($source, $destination, $image_type, $max_size, $image_width, $image_height, $quality){
  
      if($image_width &lt;= 0 || $image_height &lt;= 0){return false;} //return false if nothing to resize
  
      //do not resize if image is smaller than max size
      if($image_width &lt;= $max_size &amp;&amp; $image_height &lt;= $max_size){
          return true;
      }
  
      //Construct a proportional size of new image
      $image_scale = min($max_size/$image_width, $max_size/$image_height);
      $new_width = ceil($image_scale * $image_width);
      $new_height = ceil($image_scale * $image_height);
  
      $new_canvas = imagecreatetruecolor( $new_width, $new_height ); //Create a new true color image
      imagealphablending($new_canvas,true);
      $success = imagecopyresampled($new_canvas, $source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);
  
      return true;
  }
  if(isset($_POST['sendFile'])) { 
      $image_name = $_FILES['image_file']['name']; //file name
      $destination_folder = "folder/";
      $sm_square_size = 300; //Thumbnails will ! be cropped 
      $sm_prefix = "_sm"; //Small thumb Prefix
      $md_square_size = 600; //Thumbnails will ! be cropped 
      $md_prefix = "_md"; //Medium thumb Prefix
      $max_image_size = 1200; //Maximum image size (height and width)
      $lg_prefix = "_lg"; //Large thumb Prefix
      $jpeg_quality = 90; //jpeg quality
  
      if($image_name != "") {
          $image_size = $_FILES['image_file']['size']; //file size
          $image_temp = $_FILES['image_file']['tmp_name']; //file temp
          $image_size_info = getimagesize($image_temp); //get image size
          //echo "Image ".$image_name." Uploaded. ";
          if($image_size_info){
              $image_width = $image_size_info[0]; //image width
              $image_height = $image_size_info[1]; //image height
              $image_type = $image_size_info['mime']; //image type
          } else {
              die("Make sure image file is valid!");
          }
  
          //switch statement below checks allowed image type 
          //as well as creates new image from given file 
          switch($image_type){
              case 'image/png':
                  $image_res =  imagecreatefrompng($image_temp); break;
              case 'image/gif':
                  $image_res =  imagecreatefromgif($image_temp); break;
              case 'image/jpeg': case 'image/pjpeg':
                  $image_res = imagecreatefromjpeg($image_temp); break;
              default:
                  $image_res = false;
          }
  
          if($image_res){
              //Get file extension and name to construct new file name 
              $image_info = pathinfo($image_name);
              $image_extension = strtolower($image_info["extension"]); //image extension
              $image_name_only = strtolower($image_info["filename"]);//file name only, no extension
              $dateRec = date('d-M-Y-h-i-s');
  
              //create a random name for new image (Eg: fileName_293749.jpg) ;
              $new_file_name = $dateRec. '_' .  rand(0, 9999);
  
              $thumb_name = $new_file_name.$sm_prefix.'.'.$image_extension;
              $medium_name = $new_file_name.$md_prefix.'.'.$image_extension;
              $large_name = $new_file_name.$lg_prefix.'.'.$image_extension;
  
              $thumb_path = $destination_folder.$thumb_name;
              $medium_path = $destination_folder.$medium_name;
              $large_path = $destination_folder.$large_name;
  
  
              $ftp_server = "";
              $ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
              $ftp_username = "";
              $ftp_userpass = "";
              $login_conn = ftp_login($ftp_conn, $ftp_username, $ftp_userpass) or die("Could not connect to ftp login");
              if((!$ftp_conn) || (!$login_conn)) {
                  print "FTP connection failed!"; exit();
              } else {
                  // upload a file
  
                  if(thumb_resize_image_new($image_res, $image_temp, $image_type, $md_square_size, $image_width, $image_height, $jpeg_quality)) { 
                      echo "thumb created. $success &lt;br /&gt;";
                  } else { 
                      die('Error Creating thumbnail: '.$thumb_path.'&lt;br /&gt;'); 
                  }
  
                  if(ftp_put($ftp_conn, $thumb_path, $image_temp, FTP_BINARY)) {
                      echo "Successfully uploaded $thumb_name &lt;hr /&gt;";
                  } else {
                      echo "There was a problem while uploading $thumb_name into $thumb_path &lt;hr /&gt;";
                  }
  
                  if(ftp_put($ftp_conn, $medium_path, $image_temp, FTP_BINARY)) {
                      echo "Successfully uploaded $medium_name &lt;hr /&gt;";
                  } else {
                      echo "There was a problem while uploading $medium_name into $medium_path &lt;hr /&gt;";
                  }
  
                  if(ftp_put($ftp_conn, $large_path, $image_temp, FTP_BINARY)) {
                      echo "Successfully uploaded $large_name &lt;hr /&gt;";
                  } else {
                      echo "There was a problem while uploading $large_name into $large_path &lt;hr /&gt;";
                  }
  
              }
              ftp_close($ftp_conn);   
          }   
      }
  }
  </code></pre>
  
  <p>If anyone knows how to help fix this, or a better way of doing it, I'd forever be thankful!</p>