0

I want to rotate and save an image which was already stored in blobstore. For this I tried using images.Image.rotate method

img = images.Image(blob_key=image.blob)
img.rotate(180)
final_image = img.execute_transforms(output_encoding=images.PNG)

I don't know how to save the rotated image again to the blobstore.

Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97
Avinash Raj
  • 172,303
  • 28
  • 230
  • 274
  • I didn't yet use GCS yet, so I'm not 100% sure, but I'd try the method in this post: http://stackoverflow.com/questions/27019626/how-to-upload-image-to-the-cloud-storage-via-app-engine – Dan Cornilescu Jan 06 '16 at 16:01
  • @DanCornilescu we are currently using blobstore not GCS,, – Avinash Raj Jan 07 '16 at 02:49

2 Answers2

1

A transformed image is just a collection of bytes that you can write back to the Cloud Storage - as a new object or overwrite an existing one (e.g. cloudstorage.open with mode set to "w" using Python GS Client).

Andrei Volgin
  • 40,755
  • 6
  • 49
  • 58
  • My answer is the same - a transformed image is bytes. Save them to the Blobstore, if you prefer, although I would recommend moving to GCS. – Andrei Volgin Jan 07 '16 at 10:22
  • ya, I managed to store the converted image using your method. BUt it's still in binary/octet form. I'm struggling to convert it to jpeg. My BLobstore viewer fails to show the image inline because it's not in jpeg format. But if I download and view it in an image viewer, it seems fantastic (img_in_rotated_form)., – Avinash Raj Jan 07 '16 at 10:25
  • Of course - it's a blob. You will need to set the correct headers, including "Content-Type", when returning this blob to a browser. You can also set a file name and tell the browser whether to render or save the file using "Content-Disposition" header. – Andrei Volgin Jan 07 '16 at 10:29
  • got that http://stackoverflow.com/a/34653324/3297613 . But donno how to set the filename.. – Avinash Raj Jan 07 '16 at 11:17
1

Writing to the blobstore used to be possible using the Files API, which is now deprecated.

You can use GCS instead for writing the image (GCS is recommended over Blobstore anyways).

You can still keep the blobstore API with GCS if you want. I think it should be possible to even mix blobstore and GCS transparently for your users so that you don't have to migrate all your existing images from the blobstore to GCS.

Community
  • 1
  • 1
Dan Cornilescu
  • 39,470
  • 12
  • 57
  • 97