如何用Amazon S3替换PHP imagecopyresampled?

我正在使用jquery文件上传脚本,并已成功将主图像上传到Amazon S3。 我现在正在尝试将多个图像大小换成上传到S3中的子文件夹或对象。

在UploadHandler.php文件中的create_scaled_image函数内部,如何用S3调用替换imagecopyresampled调用? 这有可能吗?

以下是图像resize并将文件写出的内容:

$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); 

我可以以某种方式调整内存中的图像大小,然后将文件保存到我的S3对象?

  $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 } 

您可以捕获imagejpeg()的输出和相关的保存函数,以生成图像文件内容的内存中表示。 我不知道s3库是否允许你上传一个字符串,而不是只是将它指向一个文件,但它会是这样的:

 ... 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