【问题标题】:How to replace PHP imagecopyresampled with Amazon S3?如何用 Amazon S3 替换 PHP imagecopyresampled?
【发布时间】:2013-04-10 08:17:42
【问题描述】:

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

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

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

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

【问题讨论】:

  • 你好 Paul 我也在使用 jqueryfileupload,我在将插件与 AWS 集成以获取图像路径时遇到问题。uploadHandler.php 有一个 options 数组,其中包含 upload_dirupload_url .我有一个问题发布here
  • 如果您可以分享您为实现调整大小功能所做的类修改,那对我们将有很大帮助。我对同一张贴here有一个问题@

标签: php jquery amazon-s3 jquery-file-upload


【解决方案1】:

您可以捕获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

【讨论】:

  • 你好@Marc B 如果你能帮助我完成你为实现调整大小功能所做的类修改,这对我们有很大帮助。我对here@
猜你喜欢
  • 2018-11-04
  • 2013-03-02
  • 2018-02-27
  • 2016-10-30
  • 2010-10-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多