Cloud Storage 存储桶必须使用精细的访问控制列表,以确保 Images API 正常工作。对于已配置为使用统一存储桶级访问权限的存储桶,Images API 将无法提取该存储桶中的图片并会抛出 TransformationError 错误消息。如果您的存储桶正是以这种方式进行配置的,您可以停用统一存储桶级访问权限。
=sxx,其中 xx 是 0-2560 范围内的整数,表示图片最长边的长度(以像素为单位)。例如,如果添加 =s32,则图片的最长边将被调整为 32 像素。
=sxx-c,其中 xx 是 0-2560 范围内的整数,表示剪裁后的图片大小(以像素为单位);-c 用于指示系统对图片进行剪裁。
# Resize the image to 32 pixels (aspect-ratio preserved)
http://lhx.ggpht.com/randomStringImageId=s32
# Crop the image to 32 pixels
http://lhx.ggpht.com/randomStringImageId=s32-c
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-04。"],[[["\u003cp\u003eThe Images API enables serving and manipulating images directly from Google Cloud Storage or Blobstore, with support for various formats like JPEG, PNG, and WEBP.\u003c/p\u003e\n"],["\u003cp\u003eCloud Storage buckets must use fine-grained Access Control Lists for the Images API to function correctly; uniform bucket-level access can cause errors and should be disabled.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eimage.ServingURL\u003c/code\u003e function generates stable, public URLs for serving resized or cropped image thumbnails, offloading CPU and dynamic serving load from your application.\u003c/p\u003e\n"],["\u003cp\u003eImages can be dynamically resized or cropped by adding arguments such as \u003ccode\u003e=sxx\u003c/code\u003e or \u003ccode\u003e=sxx-c\u003c/code\u003e to the serving URL, where \u003ccode\u003exx\u003c/code\u003e represents the desired pixel dimension.\u003c/p\u003e\n"],["\u003cp\u003eTo properly remove images, you should use the \u003ccode\u003eimage.DeleteServingURL\u003c/code\u003e function instead of directly deleting images from Cloud Storage or Blobstore, as direct deletion can leave images accessible through their serving URLs.\u003c/p\u003e\n"]]],[],null,["# Images API for legacy bundled services\n\nThe Images API provides the ability to serve images directly from [Google Cloud\nStorage](/appengine/docs/legacy/standard/go111/googlecloudstorageclient/read-write-to-cloud-storage)\nor Blobstore, and to manipulate those images on the fly. To view\nthe contents of the `image` package, see the [`image` package\nreference](/appengine/docs/legacy/standard/go111/reference/latest/image).\n\nCloud Storage buckets **must** use fine-grained [Access Control Lists](/storage/docs/access-control/create-manage-lists) for the Images API to work. For buckets that have been configured for uniform bucket-level access, the Images API will not be able to fetch images in that bucket and throws the error message `TransformationError`. If your bucket is configured in this manner, you can [disable uniform bucket-level access](/storage/docs/uniform-bucket-level-access#set).\n| This API is supported for first-generation runtimes and can be used when [upgrading to corresponding second-generation runtimes](/appengine/docs/standard/\n| go\n| /services/access). If you are updating to the App Engine Go 1.12+ runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/go-differences) to learn about your migration options for legacy bundled services.\n\nImage formats\n-------------\n\nThe service accepts image data in the JPEG, PNG, WEBP, GIF (including animated\nGIF), BMP, TIFF and ICO formats. Transformed images can be returned in the JPEG,\nWEBP and PNG formats.\n\nIf the input format and the output format are different, the service converts\nthe input data to the output format before performing the transformation.\n| **Note:** The Images service does not support multilayer TIFF images.\n\nServing and re-sizing images\n----------------------------\n\nThe [`image.ServingURL`](/appengine/docs/legacy/standard/go111/reference/latest/image#google_golang_org_appengine_image_ServingURL)\nfunction allows you to generate a stable, dedicated URL for serving web-suitable\nimage thumbnails.\n\nYou can store a single copy of your original image in\nBlobstore, and then request a high-performance per-image URL that can serve the\nimage resized and/or cropped automatically. Serving from this\nURL does not incur any CPU or dynamic serving load on your application (though\nbandwidth is still charged as usual).\n\nThe URL returned by the function is always public, but not guessable; private\nURLs are not currently supported. If you wish to stop serving the URL, delete it\nusing the\n[`image.DeleteServingURL`](/appengine/docs/legacy/standard/go/images/reference#DeleteServingURL)\nfunction.\n\nIf you pass an\n[`image.ServingURLOptions`](/appengine/docs/legacy/standard/go111/reference/latest/image#google_golang_org_appengine_image_ServingURLOptions)\nvalue to the function, it returns a URL encoded with those options. If you pass\n`nil`, the function returns the default URL for the image, for example:\n\n\u003cbr /\u003e\n\n```\nhttp://lhx.ggpht.com/randomStringImageId\n```\n\nYou can resize and crop the image dynamically by specifying the arguments in the\nURL. The available arguments are:\n\n- `=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.\n- `=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.\n\n**Important:** Only the resize and crop arguments listed above are supported. Using any other arguments might result in breaking failures. \n\n```\n# Resize the image to 32 pixels (aspect-ratio preserved)\nhttp://lhx.ggpht.com/randomStringImageId=s32\n\n# Crop the image to 32 pixels\nhttp://lhx.ggpht.com/randomStringImageId=s32-c\n```\n\nServing images from Cloud Storage using the Blobstore API\n---------------------------------------------------------\n\nIf you are using Cloud Storage as a data store and serving the images using the\nBlobstore API, you need to [create a blob key for the Cloud Storage object](/appengine/docs/legacy/standard/go111/blobstore).\n\nA note about deletion\n---------------------\n\nTo stop serving an image stored in Cloud Storage or Blobstore call\nthe\n[`image.DeleteServingURL`](/appengine/docs/legacy/standard/go111/reference/latest/image#google_golang_org_appengine_image_DeleteServingURL)\nfunction.\n\nYou should avoid directly deleting images in Cloud Storage or Blobstore as doing\nso can leave them accessible through the serving URL.\n\nServing URLs will stop working if the application that created them is disabled\nor deleted, even if the underlying image remains available."]]