在Google Cloud Storage中调整图像大小

huangapple go评论98阅读模式
英文:

Resize image in Google Cloud Storage

问题

appengine/image包在处理存储在Blobstore中的图像时效果很好。然而,对于存储在Google Cloud Storage中的图像,有什么好的方法可以调整大小呢?

英文:

The appengine/image package works fine with images stored in Blobstore. However, what would be a good approach to resize images stored in Google Cloud Storage?

答案1

得分: 1

您可以使用相同的图像服务与Google Cloud Storage一起使用,特别是如果您使用Blobstore API上传图像。

Java示例代码:

String fullName = "/gs/" + bucketName + "/" + objectName;
Image picture = ImagesServiceFactory.makeImageFromFilename(fullName);
Transform resize = ImagesServiceFactory.makeResize(maxWidth, maxHeight);
picture = imagesService.applyTransform(resize, picture);

在Go语言中,您可以使用BlobKeyForFile函数:

BlobKeyForFile函数返回Google Storage文件的BlobKey。文件名应该是形如"/gs/bucket_name/object_name"的格式。

英文:

You can use the same Image Service with the Google Cloud Storage, especially if you use Blobstore API for uploading images.

A sample code in Java:

String fullName = "/gs/" + bucketName + "/" + objectName;
Image picture = ImagesServiceFactory.makeImageFromFilename(fullName);
Transform resize = ImagesServiceFactory.makeResize(maxWidth, maxHeight);
picture = imagesService.applyTransform(resize, picture);

In Go, you can use BlobKeyForFile function:

> BlobKeyForFile returns a BlobKey for a Google Storage file. The
> filename should be of the form "/gs/bucket_name/object_name".

答案2

得分: 0

图像裁剪功能在现在实现起来相当容易。然后,您可以对图像进行任何操作 - 将其存储回Google Storage或立即返回给客户端。更重要的是,您可以轻松将该功能部署到任何基于云的无服务器解决方案中。我使用Cloud Run,因为它是基于Docker的,因此可以在任何地方进行移植。

我有一个服务,我们使用nodejs/sharp进行基于图像的裁剪,并部署到Google Cloud Run中。您可以直接使用它。其中没有任何特定于项目的硬编码内容。

英文:

Image cropping functionality is fairly easy to implement these days. You can then do whatever you want with the image - store it back to Google Storage or return it immediately to the client.
What's more, you can easily deploy that functionality to any cloud-based serverless solution.I was using Cloud Run because it's Docker-based and hence can be ported anywhere potentially.

I have a service that we use for image cropping based on nodejs/sharp and deployed into Google Cloud Run. You can use it as-is. There's nothing project-specific hardcoded in it.

huangapple
  • 本文由 发表于 2014年4月30日 08:39:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/23377736.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定