1

I am currently trying to deploy a python(2.7) application on the GAE, but I seem to have run into a wall doing so.
In the application I need to apply some transformations on an image's data which I have retrieved in the form of an array of bytes. I proceeded as pointed out by the OP of this question. Everything seems to go fine, until I wish to retrieve back the image's data from the PIL.Image object. The code is:

def transform_image(im_data,ratio):
    im = Image.open(BytesIO(im_data))
    w,h = im.size
    im = im.crop((0,0,w,h-20))
    new_b_io = BytesIO()
    im.save(new_b_io,format='JPEG')
    im.close()
    return new_b_io.getvalue()
    #I write this data to a new '.jpg' file on my GCS bucket.

Looking at my GAE application logs, the exception being raised is:

UnsupportedOperation: fileno

This is an identified bug with the PIL version 1.1.7 (the only PIL version available with GAE), as pointed out here.
Looking everywhere, all I could manage to understand is to use a more latest version of PIL (preferably Pillow), but as one would imagine, our friends at Google haven't made that an option. I could move to the Google's Image Processing API, but I'd appreciate if I could make my way through with PIL.

I'd appreciate if someone could walk me through this dilemma.

Thanks for your time.

Community
  • 1
  • 1
Tanmay Garg
  • 801
  • 11
  • 20
  • try using `StringIO()` instead of `BytesIO()` – atimothee Nov 25 '16 at 09:59
  • If you are using native code (like PIL or pillow do) I think App Engine Flexible Environment better suits your needs, as you will not be restricted to pure-Python or Google provided libraries like on Standard Environment. – dyeray Nov 25 '16 at 11:46

0 Answers0