2

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

在 UploadHandler.php 文件中的create_scaled_image函数中,如何将 imagecopyresampled 调用替换为 S3 调用?这甚至可能吗?

这是图像调整大小并将文件写入的内容:

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

1 回答 1

2

您可以捕获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
于 2013-04-17T14:28:10.210 回答