Reputation: 785
I have an iOS app in which users upload images directly to Google Cloud Storage. I achieve this by using the function blobstore.create_upload_url
in my Python Google App Engine backend, and sending the URL to my app.
However, displaying these images back to the user is taking too long as the images are too large, so I realize I need to compress these images in Google Cloud Storage.
Do you know how this can be achieved programmatically? I know I can execute terminal commands to get compress and re-upload images to Google Cloud Storage but I need to do this programmatically within my app.
Upvotes: 2
Views: 3704
Reputation: 482
I'm not entirely sure what type of compression you are looking for, but app engine provides a image service allowing you to resize the images.
From their docs, you can use the image service with the blob store as a source -
The Images service can use a Blobstore value as the source of a transformation. The source image can be as large as the maximum size for a Blobstore value. The Images service still returns the transformed image to the application, so the transformed image must be smaller than 32 megabytes. This is useful for making thumbnail images of large photographs uploaded by users.
Something along these lines -
from google.appengine.api import images
image = Image(blob_key=YOUR_BLOB_KEY)
image.resize(width=YOUR_WIDTH, height=YOUR_HEIGHT)
compressed_image = image.execute_transforms(output_encoding=images.JPEG)
Here's an overview of the API and list api reference -
https://cloud.google.com/appengine/docs/standard/python/images/ https://cloud.google.com/appengine/docs/standard/python/refdocs/google.appengine.api.images
Upvotes: 1