如何更换PHP imagecopyresampled与Amazon S3? [英] How to replace PHP imagecopyresampled with Amazon S3?

查看:149
本文介绍了如何更换PHP imagecopyresampled与Amazon S3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 jQuery的文件上传脚本,并已经成功上传主图像到Amazon S3。我现在想换出多种图像大小上传到子文件夹或对象的S3。

create_scaled_image 功能的Upl​​oadHandler.php文件我怎么更换 与S3呼叫imagecopyresampled电话吗?这甚至可能?

下面是对图像大小调整和文件写出:

  $成功= $ 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);
    //释放内存(imagedestroy不删档):
    @imagedestroy($ src_img);
    @imagedestroy($ new_img);
 

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

  $桶=pics.mysite.com;

 $文件=?
 $ uploaded_file =?
 $响应= $ S3-> create_object($桶,$文件,​​阵列('文件上传'=> $ uploaded_file,'ACL'=> AmazonS3 :: ACL_PUBLIC));
 如果($响应 - > isOK()){
     //成功
 }
 

解决方案

您可以捕捉 imagejpeg输出()和相关的保存功能,产生一个内存重的图像文件的内容presentation。我不知道这是否S3库允许你上传一个字符串,而不是仅仅指向它在一个文件,但它会去是这样的:

  ...图像操作
ob_start()函数;
imagejpeg($ IMG); //出$ IMG GD手柄为.jpg文件
$ JPG = ob_get_clean();

$ S3->上传(....'Filedata上'=> $ JPG);
                 ^^^^^^^^^^ ---无论it'be在S3 LIB从字符串中发送
 

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
 }

解决方案

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

这篇关于如何更换PHP imagecopyresampled与Amazon S3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆