本文介绍了通过请求 URL 调整 Google Cloud 图片大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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?

解决方案

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 from 0–2560 representing the cropped image size in pixels, and -c tells the system to crop the image.

这篇关于通过请求 URL 调整 Google Cloud 图片大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 09:10