title: Amazon S3 Upload PDF and Create Cover Image
body: <p>I have the following bit of code which uploads a PDF to Amazon S3, what I need to do is create an image from the 1st page of the PDF and upload that to s3 as well.</p>
  
  <pre><code>//instantiate the class
  $s3 = new S3(awsAccessKey, awsSecretKey);
  
  //check whether a form was submitted
  if($_SERVER['REQUEST_METHOD'] == "POST")
  {
      //retreive post variables
      $fileName = $_FILES['file']['name'];
      $fileTempName = $_FILES['file']['tmp_name'];
      $fileSize = $_FILES['file']['size'];
  
      $extension=end(explode(".", $fileName));
      $rand = rand(1,100000000);
      $sha1 = sha1($rand);
      $md5 = md5($sha1);
      $fName = substr($md5, 0, 20);       
      $finalName = $fName.'.'.$extension;
  
      //create a new bucket
      $s3-&gt;putBucket("bucket", S3::ACL_PUBLIC_READ);
  
      //move the file
      if ($s3-&gt;putObjectFile($fileTempName, "bucket", 'publications/'.$finalName, S3::ACL_PUBLIC_READ)) {
          $s3file='http://bucket.s3.amazonaws.com/publications/'.$finalName;
          $aS3File = 'publications/'.$finalName;
  
          $im = new imagick($s3file[0]); 
          // convert to jpg 
          $im-&gt;setImageColorspace(255); 
          $im-&gt;setCompression(Imagick::COMPRESSION_JPEG); 
          $im-&gt;setCompressionQuality(75); 
          $im-&gt;setImageFormat('jpeg'); 
          //resize 
          $im-&gt;resizeImage(640, 877, imagick::FILTER_LANCZOS, 1);  
          //write image on server (line 54) 
          $s3-&gt;putObjectFile("","bucket", 'publications/'.$im-&gt;writeImage($fName.'.jpg'), S£::ACL_PUBLIC_READ);
  
      }else{
          echo "&lt;strong&gt;Something went wrong while uploading your file... sorry.&lt;/strong&gt;";
      }
  </code></pre>
  
  <p>I have replace my actual bucket name with 'bucket' for security, can anyone tell me what I am doing wrong here as I get the following error:</p>
  
  <blockquote>
    <p>PHP Fatal error:  Uncaught exception 'ImagickException' with message
    'Unable to read the file: h' in
    /var/www/ams/pub-new-issue.php:45\nStack trace:\n#0
    /var/www/ams/pub-new-issue.php(45): Imagick->__construct('h')\n#1
    {main}\n  thrown in /var/www/ams/pub-new-issue.php on line 45,</p>
  </blockquote>
  
  <p>thanks</p>