Resize image in Google Cloud Storage

2019-07-25 10:17发布

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条回答
Root(大扎)
2楼-- · 2019-07-25 10:57

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".

查看更多
登录 后发表回答