Using Python Image Library PIL and Google App Engine Blobstore…
This:
img = images.Image(blob_key=image)
logging.info(img.size)
self.response.headers['Content-Type'] = 'image/jpeg'
self.response.out.write(img)
Has Attribute error:
AttributeError: 'Image' object has no attribute 'size'
So the Image instance from google app engine does not have size?
So then how does this work:
img = images.Image(blob_key=image)
img.resize(width, height)
img.im_feeling_lucky()
thumbnail = img.execute_transforms(output_encoding=images.JPEG)
self.response.headers['Content-Type'] = 'image/jpeg'
self.response.out.write(thumbnail)
What am I missing?
EDIT:
The fix was using the get_serving_url and not use my image server as proposed by @voscausa.
Due to the fact that my object was parsed by jinja2 templating it was impossible to create a Image object via jinja2.
So the final solution worked as below:
class Mandelbrot(db.Model):
image = blobstore.BlobReferenceProperty()
@property
def image_url(self):
return images.get_serving_url(self.image)
This way I could parse the image url to my page like:
<img src=
{% if mandelbrot.image %}
"{{ mandelbrot.image_url }}"
{% else %}
"./assets/img/preloader.gif"
{% endif %}
/>
I’am not familiair with PIL, because I use another solution from Google for serving and sizing images.
Google can serve the images for you, using Google High Performance Image serving. This means:
Here is an example. You can change the =s0, to change the size. s0 returns the original size.
get_serving_url docs: https://developers.google.com/appengine/docs/python/images/functions
Code :