2

I'm using the jquery file upload script and have had success uploading the main image to Amazon S3. I'm now trying to swap out the multiple image sizes for uploads to sub folders or objects in S3.

Inside the create_scaled_image function in the UploadHandler.php file how do I replace the imagecopyresampled call with an S3 call? Is this even possible?

Here is what does the image resizing and writes the file out:

 $success = $src_img && @imagecopyresampled(
        $new_img,
        $src_img,
        $dst_x,
        $dst_y,
        0,
        0,
        $new_width,
        $new_height,
        $img_width,
        $img_height
    ) && $write_image($new_img, $new_file_path, $image_quality);
    // Free up memory (imagedestroy does not delete files):
    @imagedestroy($src_img);
    @imagedestroy($new_img);

Can I somehow resize the image in memory and then save the file to my S3 object?

 $bucket = "pics.mysite.com";

 $file = ??
 $uploaded_file = ??
 $response = $s3->create_object($bucket, $file, array('fileUpload' => $uploaded_file, 'acl' => AmazonS3::ACL_PUBLIC));
 if ($response->isOK()) {
     //success
 }
Paul
  • 11,671
  • 32
  • 91
  • 143
  • Hello Paul I am also working with jqueryfileupload and I am issues with integrating the plugin with AWS for image paths.The uploadHandler.php has a `options` array which holds the `upload_dir` and `upload_url`. I have a question posted [here](http://stackoverflow.com/questions/17490045/integrating-jqueryupload-plugin-with-aws-php-sdk-to-upload-images-to-s3) – KillABug Jul 07 '13 at 07:02
  • If you can share the class modifications you made to achieve the resizing functionality,it would be a great help to us.I have a question for the same posted [here](http://stackoverflow.com/questions/17544628/image-upload-performance-issue-with-amazon-s3-and-jqueryfileupload-plugin) – KillABug Jul 09 '13 at 10:59

1 Answers1

2

You can capture the output of imagejpeg() and the related save functions to produce an in-memory representation of the image file's contents. I don't know if that s3 library allows you to upload a string, rather than just pointing it at a file, but it'd go something like this:

... image operations
ob_start();
imagejpeg($img); // out $img gd handle as a .jpg file
$jpg = ob_get_clean();

$s3->upload(.... 'filedata' => $jpg);
                 ^^^^^^^^^^---whatever it'be in the S3 lib to send from a string
Marc B
  • 356,200
  • 43
  • 426
  • 500
  • Hello @Marc B If you can help me with the class modifications you made to achieve the resizing functionality,it would be a great help to us.I have a question for the same posted [here](http://stackoverflow.com/questions/17544628/image-upl+oad-performance-issue-with-amazon-s3-and-jqueryfileupload-plugin) – KillABug Jul 09 '13 at 10:57