2017-01-10 40 views
2

我已經使用GAE圖像api成功調整了圖像大小,現在我又想在blob-store中存儲已調整大小的圖像,我該怎麼做才能提供幫助。這裏是代碼在blobstore webapp2上存儲已調整大小的圖像

img = images.Image(blob_key=user.profile_pic) 
img.resize(width=80, height=100) 
img.im_feeling_lucky() 
thumbnail = img.execute_transforms(output_encoding=images.JPEG) 

如果我使用此代碼它顯示調整大小的圖像,但我想再次存儲在blob商店。

self.response.headers['Content-Type'] = 'image/jpeg' 
self.response.out.write(thumbnail) 
+2

Blobstore不允許您寫入圖像。要使用Blobstore,您必須上傳調整大小的圖像。更好的方法是使用GCS(Google雲存儲)。您可以使用blobstore API將Blob存儲在GCS中,並且可以使用Google Cloud Storage客戶端庫編寫gcs文件。 – voscausa

+0

[如何保存存儲在GAE Blobstore中的旋轉圖像?](http://stackoverflow.com/questions/34633213/how-to-save-a-rotated-image-which-was-stored- in-gae-blobstore) –

+0

@DanCornilescu有沒有一種方法來獲取調整大小的圖像的服務網址。以便我們可以顯示帶有其他數據的已調整大小的圖像。 –

回答

1

下面是獲取服務url後的解決方案,我們可以簡單地在鏈接中傳遞參數來對圖像執行操作。

img = images.Image(blob_key=user.profile_pic) 
url = images.get_serving_url(user.profile_pic)   
url = url + "=s80" #if i want a thumbnail