1

イメージを Amazon S3 にコピーしようとしていますが、次のようにイメージからバイナリ データを渡すことができればうまくいきます。

$binary = file_get_contents($image_location);

$response = $s3->create_object(AWS_S3_BUCKET, $image_name, array( 'body' => $binary, 'contentType' => $info['mime'], 'acl' => AmazonS3::ACL_PUBLIC));

imagecreatefromjpeg から同じバイナリ データを取得するにはどうすればよいですか? もっと簡単な方法はありますか?

私は現在、この方法で画像リソースを取得しています:

private function GetImageResource($image, $extension){
    switch($extension){
        case "jpeg":
        case "jpg":
            @ini_set('gd.jpeg_ignore_warning', 1);
            $resource = imagecreatefromjpeg($image);
            break;
        case "gif":
            $resource = imagecreatefromgif($image);
            break;
        case "png":
            $resource = imagecreatefrompng($image);
            break;
    }
    return $resource;
}
4

1 に答える 1

1

The expression "binary data" is ambiguous, everything is binary here.

The PHP function imagecreatefromjpeg() opens a file, reads its (binary) data ("jpeg image"), and converts it to some binary representation that PHP uses ("php image"). I don't think you can/should pass that binary data to Amazon, when it's expecting a "raw image". If you have a php image and want to use $s3->create_object(), then I'd reconvert it to some binary image format (eg imagejpeg() ) and send that data.

于 2013-04-26T19:42:53.373 に答える