简体   繁体   English

在 Google Cloud Storage 中调整图像大小

[英]Resize image in Google Cloud Storage

The appengine/image package works fine with images stored in Blobstore. appengine/image 包适用于存储在 Blobstore 中的图像。 However, what would be a good approach to resize images stored in Google Cloud Storage?但是,调整存储在 Google Cloud Storage 中的图像大小的好方法是什么?

You can use the same Image Service with the Google Cloud Storage, especially if you use Blobstore API for uploading images.您可以将相同的图像服务与 Google Cloud Storage 一起使用,尤其是当您使用 Blobstore API 上传图像时。

A sample code in Java: 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:在 Go 中,您可以使用BlobKeyForFile函数:

BlobKeyForFile returns a BlobKey for a Google Storage file. BlobKeyForFile 返回 Google Storage 文件的 BlobKey。 The filename should be of the form "/gs/bucket_name/object_name".文件名的格式应为“/gs/bucket_name/object_name”。

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.然后,您可以对图像执行任何您想要的操作 - 将其存储回Google Storage或立即将其返回给客户端。 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.更重要的是,您可以轻松地将该功能部署到任何基于云的无服务器解决方案。我使用Cloud Run是因为它基于 Docker,因此可以潜在地移植到任何地方。

I have a service that we use for image cropping based on nodejs/sharp and deployed into Google Cloud Run.我有一个服务,用于基于nodejs/sharp图像裁剪并部署到 Google Cloud Run。 You can use it as-is.您可以按原样使用它。 There's nothing project-specific hardcoded in it.其中没有任何特定于项目的硬编码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM