2012-08-08 12 views
1

我使用下面的代碼成功發佈到我的谷歌AppEngine應用程式的圖像來調整圖片的大小:GAE(AppEngine上)出現在發佈

def post(self): 

    image_data = self.request.get('file') 
    file_name = files.blobstore.create(mime_type='image/png') 

    # Open the file and write to it 
    with files.open(file_name, 'a', exclusive_lock=True) as f: 
     f.write(image_data) 

    # Finalize the file. Do this before attempting to read it. 
    files.finalize(file_name) 

    # Get the file's blob key 
    blob_key = files.blobstore.get_blob_key(file_name) 
    self.response.out.write(images.get_serving_url(blob_key)) 

然而,當我瀏覽通過get_serving_url(),在輸出的URL圖像是總是在降低分辨率。 爲什麼?我檢查並重複檢查發佈的圖像尺寸是否正確(來自iPhone相機,因此約爲3200x2400分辨率)。然而,服務的圖像始終是512x384。

我對GAE相當陌生,但我認爲上面的代碼應該將圖像存儲在BlobStore而不是數據存儲區中,從而規避1 MB的限制。

有沒有人有任何想法會發生什麼?

乾杯, 佈雷特

回答

3

實測值的溶液中。或者至少有一些適合我的東西。 我在=sXX附加到所提供的URL的末尾,AppEngine將以XX分辨率提供圖片。舉例來說,如果線路:

self.response.out.write(images.get_serving_url(blob_key))

回報: http://appengine.sample.com/appengineurlkey

然後調用上述結果的URL時,圖像將是一個較低分辨率圖像,

然後通過調用URL : http://appengine.sample.com/appengineurlkey**=s1600**

由此產生的服務圖像將在1600x1200分辨率(或類似分辨率受限於維持寬高比)。

+3

= s0將服務於原始大小 – Greg 2012-08-08 17:42:30

0

您所瀏覽的get_serving_url在文檔中https://developers.google.com/appengine/docs/python/images/functions

解釋什麼解釋:

調整或剪裁圖像時,必須使用一個整數0指定新的大小1600.最大尺寸在IMG_SERVING_SIZES_LIMIT中定義。 API將圖像大小調整爲提供的值,將指定大小應用於圖像的最長維度並保留原始高寬比。

如果您想提供全尺寸圖片,另一種方法是將圖片直接上傳到blobstore,然後從那裏提供。 (即,完全繞過圖像API)。參見https://developers.google.com/appengine/docs/python/blobstore/overview

相關問題