gpt4 book ai didi

php - 如何用 Amazon S3 替换 PHP imagecopyresampled?

转载 作者:行者123 更新时间:2023-12-01 04:14:31 27 4
gpt4 key购买 nike

我正在使用jquery file upload脚本并已成功将主图像上传到 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
}

最佳答案

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

关于php - 如何用 Amazon S3 替换 PHP imagecopyresampled?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16062246/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com