如何使用PHP使用imagecopyresampled调整图像大小,然后获取内容

如何使用PHP使用imagecopyresampled调整图像大小,然后获取内容,php,image-processing,amazon-s3,file-get-contents,Php,Image Processing,Amazon S3,File Get Contents,我目前正在调整图像大小并将其写入文件。此后,我需要将其存储在Amazon中,因此我只需要调整大小后的图像的内容。不先将其写入文件就可以完成此操作吗 这就是我当前的代码: $success = $src_img && @imagecopyresampled( $new_img, $src_img, $dst_x, $dst_y, 0, 0, $new_width,

我目前正在调整图像大小并将其写入文件。此后,我需要将其存储在Amazon中,因此我只需要调整大小后的图像的内容。不先将其写入文件就可以完成此操作吗

这就是我当前的代码:

    $success = $src_img && @imagecopyresampled(
        $new_img,
        $src_img,
        $dst_x,
        $dst_y,
        0,
        0,
        $new_width,
        $new_height,
        $img_width,
        $img_height
    ) && imagejpeg($new_img, $new_file_path, $image_quality);

    // Free up memory (imagedestroy does not delete files):
    @imagedestroy($src_img);
    @imagedestroy($new_img);

    $type = $this->get_file_type($new_file_path);
    $binary = file_get_contents($new_file_path);

    $image = $this->get_user_path() . $version . '/' . $file_name;

    $response = $this->S3->create_object(AWS_S3_BUCKET, $image, array( 'body' => $binary, 'contentType' => $type, 'acl' => AmazonS3::ACL_PUBLIC));
    if ($response->isOK()) {
        // success
    }

如何在不首先将文件写入文件的情况下获取文件内容?

您需要使用输出缓冲区命令包装
imagejpeg($new\u img,NULL,$image\u quality)

ob_start();
imagejpeg($new_img, NULL, $image_quality);
$binary = ob_get_clean();