通过请求URL调整Google Cloud图像的大小? [英] Resize Google Cloud images via request URL?
问题描述
我需要图像的CDN,可以从URL参数调整图像的大小.因此,例如,如果我想要一个400px宽的版本,我会使用www.cdn.com/image-400
,如果我想要一个200px的版本,它将是www.cdn.com/image-200
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
通过查看此博客文章,看来Google Cloud可以做到这一点:
From looking at this blog post it seems Google Cloud can do this:
但是我在理解这篇文章时遇到了麻烦,我想知道它是否过时了.指向Google文档的链接之一说,您应该改为使用Google Cloud Storage https: //cloud.google.com/appengine/docs/standard/python/blobstore/
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/
我遇到了这两个SO问题,但它们似乎给出了相反的答案:
I came across these 2 SO questions but they seem to give opposite answers:
Google Cloud可以根据URL调整图像大小吗?如果是这样,那您该怎么办?我在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?
推荐答案
首先可以,但是作为您共享的第一个SO答案并没有直接实现,并且您注意到该过程并不那么简单将= sxx添加到存储桶的网址中.
因此,编写https://storage.googleapis.com/bucketname/file.jpg=sxx
无效.
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.
为了创建能够支持此功能的URL,您必须使用Images API for Java,特别是getServingUrl()
GO 或
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
其中xx是0到2560之间的整数,代表图像最长边的长度(以像素为单位).例如,添加= s32会调整图像的大小,使其最长尺寸为32像素.
=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
,其中xx是整数
m 0–2560代表裁剪的图像大小(以像素为单位),-c告诉系统裁剪图像.
=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.
这篇关于通过请求URL调整Google Cloud图像的大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!