2

I am working on an application that uses Google Cloud storage to serve my app images. The images are submitted from an android app to google app engine code that is supposed to upload the images to GCS then create a link and update in my db. This works fine.

The challenge am facing is I need different devices to serve the same image but in different dimensions. E.g device1 can request images to be served with size 300x300 while device2 can request the same image to be served with size 500x500. I have tried to google the issue but I don't seem to get a correct way to serve my image in different sizes but only got some url structure that will use a blob key then parse the size as a get parameter in the url and the image is cropped to the required dimensions. E.g. http://lh4.ggpht.com/TgjDT-cPRr6bjrpSVQeILk93o4Ouzjo1ygMB6KpmnCHhyH5vJKKRrqxCD2bC3T09CRIP6h5QFsV_l0hnhio5bN7z=s1000-c

My images' urls are in this format http://storage.googleapis.com/myappname.appspot.com/images/random_generated_imagename.jpg

Can someone suggest an idea on how I can achieve this using the url that I have?

I have tried reading image from the url, resizing it image to the size requested by the device then pushing back the image to the device but this looks tedious to me and utilizes a lot of server resources given that I can have an average of 100 connections per second requesting for images.

2

The easiest way to do this is to have Google Cloud Storage resize the image on the fly for you by creating the magic URLs you noticed. See here for Python and here for Java; no server-side processing required on your end!

0

One way is to resize the image on the fly, as already explained by Will Hayworth.

Another way, if there is a relatively small number of discrete values (i.e. the client may request 300×300 or 500×500 or 550×550, but cannot ask for 382×382), is to generate all the possible sizes when saving the image. This increases the space used by the application, but reduces the computing to a minimum. If I remember correctly, this approach is used by SquareSpace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.