title: PHP Amazon S3 upload WITH watermark
body: <p>I current have a FULLY FUNCTIONING script that uploads pictures directly to my s3 bucket from my server...</p>
  
  <p>However, I want to now start adding a watermark to every image that is uploaded.As you know upload to S3 never really stores it on the server, just as a temp file.</p>
  
  <p>Basically, I am trying to upload an image to S3 (which works already) but before, I want to add a watermark to that image (not working).</p>
  
  <p>HERE IS THE WORKING CODE THATS UPLOADS FILES TO MY S3 BUCKET:</p>
  
  <pre><code>        if (!class_exists('S3'))require_once('S3.php');
  
          //AWS access info
          if (!defined('awsAccessKey')) define('awsAccessKey', 'BLAHBLAH');
          if (!defined('awsSecretKey')) define('awsSecretKey', 'BLAHBLAH');
  
          //instantiate the class
          $s3 = new S3(awsAccessKey, awsSecretKey);
  
          $fileName = $_FILES['theFile']['name'];
          $fileTempName = $_FILES['theFile']['tmp_name'];
          $fileSize = $_FILES['theFile']['size'];
          $fileExt = substr($fileName, strrpos($fileName, '.') + 1);
          $fileExt = strtolower($fileExt);
  
          $custompostid = rand(1000000,9999999);
          $imageName = $custompostid.".".$fileExt.""; 
  
          //move the file
          if ($s3-&gt;putObjectFile($fileTempName, "BUCKETNAME", $image, S3::ACL_PUBLIC_READ, array(), $imageType)) { 
          //success
          }
          else{   
          //error
          }
  </code></pre>
  
  <p>BUT BEFORE UPLOADING A FILE, I WANT TO ADD A WATERMARK TO EVERY IMAGE. WITH THIS FUNCTION:</p>
  
  <pre><code>        // getting the image name from GET variable
          $image = $_GET['image'];
  
          // creating png image of watermark
          $watermark = imagecreatefrompng('watermark.png');  
  
          // getting dimensions of watermark image
          $watermark_width = imagesx($watermark); 
          $watermark_height = imagesy($watermark); 
  
          // creting jpg from original image
          $image_path = '/path/to/image/folder/' . $image;
          $image = imagecreatefromjpeg($image_path);
          //something went wrong
          if ($image === false) {
              return false;
          }
          // getting the dimensions of original image
          $size = getimagesize($image_path); 
          // placing the watermark 5px from bottom and right
          $dest_x = $size[0] - $watermark_width - 5; 
          $dest_y = $size[1] - $watermark_height - 5;
          // blending the images together
          imagealphablending($image, true);
          imagealphablending($watermark, true);
          // creating the new image
          imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
          imagejpeg($image); 
          // destroying and freeing memory
          imagedestroy($image); 
          imagedestroy($watermark);
  </code></pre>
  
  <p>I want to combine these two working scripts into one. I'm sure its simple, all the code is here, I just don't know how to go about linking one process to the other. This is the best I can explain this.. Thanks!</p>