Pergunta

I'm trying to copy my images to Amazon S3 and it works great if I can pass it the binary data from the image like so:

$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));

How can I get the same binary data from imagecreatefromjpeg? Is there an easier way?

I'm currently getting the image resource this way:

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;
}
Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top