2013-05-08 20 views
0

我目前正在調整圖像大小,並將其寫入文件調整與PHP的圖像。之後我就需要將它存儲在亞馬遜上,所以我需要的是調整大小的圖像的內容。這可以在沒有先寫入文件的情況下完成嗎?如何使用imagecopyresampled,然後讓內容

這是我當前的代碼看起來像:

$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 
    } 

我怎樣才能獲得該文件的內容,而不首先將其寫入文件?

回答

2

你需要換imagejpeg($new_img, NULL, $image_quality)與輸出緩衝命令:

ob_start(); 
imagejpeg($new_img, NULL, $image_quality); 
$binary = ob_get_clean(); 
相關問題