Crop Images storaged in Google Cloud storage with a given bounding box.

459 views
Skip to first unread message

Handerson Contreras

unread,
Jun 13, 2016, 12:22:57 PM6/13/16
to Google App Engine
Hello Everybody

I have a problem trying to crop images in GAE.

I'm using the Images API and adding parameters to the Url created by 

images.get_serving_url(key, size=None, crop=False, secure_url=None) method, but i need to crop with a given bounding box.

Do you know if this is possible by using get_serving_url method?

or maybe you can give me another suggestion.

Thanks

Adam (Cloud Platform Support)

unread,
Jun 13, 2016, 3:22:17 PM6/13/16
to Google App Engine
The bounding box crop is only provided by Image.crop(left, top, right, bottom), so you'd need to do this from within your own handler and serve the cropped image back. The URL returned by get_serving_url only accepts one argument for the longest side length.

A complete example of how to load an image from the Datastore and transform it is provided in the docs. The transform and response code in your handler would look something like the following:

img = images.Image(photo.full_size_image)
img
.crop(left, top, right, bottom)
thumbnail
= img.execute_transforms(output_encoding=images.JPEG)
self.response.headers['Content-Type'] = 'image/jpeg'
self.response.out.write(thumbnail)

Handerson Contreras

unread,
Jun 13, 2016, 4:07:41 PM6/13/16
to Google App Engine
so, if i want to crop an image had already storaged  in google cloud storage do I need to look for the image by using its BlobKey then crop and then save the image, again?

Nicholas (Google Cloud Support)

unread,
Jun 17, 2016, 4:38:12 PM6/17/16
to Google App Engine
In the example provided by Adam, the image is cropped within the handler and served directly in response to the request.  This will in effect crop the original image each time to serve the cropped version you are looking for.  If you plan on serving the same cropped image repeatedly, then yes.  I would indeed suggest that you store it and serve the cropped version directly.  This will occupy more storage in total having both images in storage but have faster handler response time as it will not need to crop the image each time.

To make an informed decision on which is the best choice for you, I'd suggest trying both and comparing the additional storage space required to the additional request latency for live cropping.


On Monday, June 13, 2016 at 12:22:57 PM UTC-4, Handerson Contreras wrote:
Message has been deleted

Handerson Contreras

unread,
Jun 18, 2016, 9:19:05 AM6/18/16
to google-a...@googlegroups.com

Thanks so much for your answer Nicholas and Adam. I was considering save the cropped image.

--
You received this message because you are subscribed to a topic in the Google Groups "Google App Engine" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-appengine/17rjUSfHIdA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-appengi...@googlegroups.com.
To post to this group, send email to google-a...@googlegroups.com.
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-appengine/a6e0678e-f1bc-4423-bc3b-4d932a3f4004%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages