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

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后登不上
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面