4
votes

I need a CDN of images where I can resize the image from URL parameter. So for instance if I wanted a 400px wide version I would use www.cdn.com/image-400 and if I wanted a 200px version it would be www.cdn.com/image-200

From looking at this blog post it seems Google Cloud can do this:

https://medium.com/google-cloud/uploading-resizing-and-serving-images-with-google-cloud-platform-ca9631a2c556

Im having trouble understanding the article however and i wonder if its out of date. One of links to Google's documentation says you should use instead use Google Cloud Storage https://cloud.google.com/appengine/docs/standard/python/blobstore/

I came across these 2 SO questions but they seem to give opposite answers:

Get resized images from Google cloud storage

Resize image in Google Cloud Storage

Can Google Cloud resize images based on the url? If so, then how can you do this? I have a bucket set up in Google Cloud Storage, can you use images from a bucket like this?

1

1 Answers

3
votes

First of all yes, it is possible, but as the first SO answer you shared it is not directly implemented and as you noticed the process it is not as straightforward as adding =sxx to an URL of a bucket. Therefore writing https://storage.googleapis.com/bucketname/file.jpg=sxx does NOT work.

In order to create a URL capable to support this features you have to make use of Images API for Java, in particular the getServingUrl() method (there is also the GO or Python version of it) that will generate a new URL with the very same shape of the URL contained in the article you shared.

Once you retrieved the URL making use of the API you will be able to get the resized images, quoting directly from the official documentation you will be able to add:

  • =sxx where xx is an integer from 0–2560 representing the length, in pixels, of the image's longest side. For example, adding =s32 resizes the image so its longest dimension is 32 pixels.

  • =sxx-c where xx is an integer fro m 0–2560 representing the cropped image size in pixels, and -c tells the system to crop the image.