2016-02-28 75 views
0

我想從AWS S3下載圖像並使用php進行處理。我使用「imagecreatefromjpeg」和「getimagesize」來處理我的圖像,但它似乎是如何使用Laravel 5處理從AWS S3下載的圖像?

Storage :: disk('s3') - > get(imageUrlonS3);

檢索二進制圖像,並給我錯誤。這是我的代碼:

function createSlices($imagePath) { 

       //create transform driver object 
       $im = imagecreatefromjpeg($imagePath); 
       $sizeArray = getimagesize($imagePath); 

       //Set the Image dimensions 
       $imageWidth = $sizeArray[0]; 
       $imageHeight = $sizeArray[1]; 

       //See how many zoom levels are required for the width and height 
       $widthLog = ceil(log($imageWidth/256,2)); 
       $heightLog = ceil(log($imageHeight/256,2)); 


       //more code here to slice the image 
       . 
       . 
       . 
       . 
      } 

      // ex: https://s3-us-west-2.amazonaws.com/bucketname/image.jpg 
      $content = Storage::disk('s3')->get(imageUrlonS3); 
      createSlices($content); 

我在這裏錯過了什麼?

感謝

+0

你能提供確切的錯誤,你看到了嗎? – Castaglia

回答

0

我想你是對你的問題是什麼問題 - 在get方法返回的自身形象,而不是圖像的位置的來源。當您將其傳遞給createSlices時,您傳遞的是二進制數據,而不是其文件路徑。在createSlices的內部,您可以撥打imagecreatefromjpeg,它需要一個文件路徑,而不是圖像本身。

如果確實如此,您應該能夠使用createimagefromstring而不是createimagefromjpeggetimagesizefromstring而不是getimagesize。函數createimagefromstringgetimagesizefromstring每個都需要圖像的二進制字符串,我相信這是你的。

這裏的相關文件:

createimagefromstring - http://php.net/manual/en/function.imagecreatefromstring.php

getimagesizefromstring - http://php.net/manual/en/function.getimagesizefromstring.php

產生的代碼可能是這個樣子:

function createSlices($imageData) { 
    $im = imagecreatefromstring($imageData); 
    $sizeArray = getimagesizefromstring($imageData); 

    //Everything else can probably be the same 
    . 
    . 
    . 
    . 
} 

$contents = Storage::disk('s3')->get($imageUrlOnS3); 
createSlices($contents); 

請注意我沒有測試過這,但我相信我在你的問題和w中能看到的我在文檔中看到這可能就是這樣做的。

+0

謝謝xjstratedgebx工作:) –