douzi8916 2013-04-17 14:04
浏览 39
已采纳

如何用Amazon S3替换PHP imagecopyresampled?

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
 }
  • 写回答

1条回答 默认 最新

  • dongliao1860 2013-04-17 14:28
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备