[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eThe App Engine API offers \u003ccode\u003eCloudStorageTools.getImageServingUrl()\u003c/code\u003e to generate URLs for serving images stored in Cloud Storage, and \u003ccode\u003eCloudStorageTools.deleteImageServingUrl()\u003c/code\u003e to stop serving them.\u003c/p\u003e\n"],["\u003cp\u003eUsing \u003ccode\u003egetImageServingUrl\u003c/code\u003e allows for dynamic resizing and cropping of images without needing to store multiple image sizes, offering a significant advantage over directly making files public.\u003c/p\u003e\n"],["\u003cp\u003eOnly the first app that calls \u003ccode\u003egetImageServingUrl\u003c/code\u003e can serve a specific image; subsequent apps must copy the image first if they need to serve it.\u003c/p\u003e\n"],["\u003cp\u003eSetting \u003ccode\u003esecure_url\u003c/code\u003e to \u003ccode\u003eTrue\u003c/code\u003e when using \u003ccode\u003egetImageServingUrl\u003c/code\u003e ensures the image can be displayed on HTTPS pages without mixed-content warnings.\u003c/p\u003e\n"],["\u003cp\u003eTo remove the actual file you must use the PHP \u003ccode\u003eunlink()\u003c/code\u003e function and not the \u003ccode\u003edeleteImageServingUrl\u003c/code\u003e.\u003c/p\u003e\n"]]],[],null,["# Serving Images\n\nThe App Engine API for Cloud Storage Tools provides convenience methods\nfor serving image files:\n\n- `CloudStorageTools.getImageServingUrl()`\n- `CloudStorageTools.deleteImageServingUrl()`\n\n| This page describes how to use the legacy bundled services and APIs. This API can only run in first-generation runtimes in the App Engine standard environment. If you are updating to the App Engine PHP 7/8 runtime, refer to the [migration guide](/appengine/migration-center/standard/migrate-to-second-gen/php-differences) to learn about your migration options for legacy bundled services.\n\n\u003cbr /\u003e\n\n| **Note:** When running your app locally on the [development server](/appengine/docs/legacy/standard/php/tools/using-local-server), you'll need to install [PIL](https://python-pillow.org/) if you wish to use the image sizing options described in this page.\n\nOne advantage of using this method to serve images over simply\n[making the files public](/appengine/docs/legacy/standard/php/googlestorage/public_access) is\nthe ability to resize and crop dynamically, without needing to store the\nimages in different sizes.\n\n[CloudStorageTools::getImageServingUrl](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.cloud_storage.CloudStorageTools#method_getImageServingUrl)\nreturns a serving URL for an image. If the image will be displayed within an\nHTTPS page, set `secure_url` to `True` to avoid mixed-content warnings.\n\nNotice that this URL is publicly readable by everyone, but it is not \"guessable\".\n| **Important:** You cannot serve an image from two separate apps; only the first app that calls `getImageServingUrl` can get the URL to serve it because that app has obtained ownership of the image to serve it. Any other app that calls `getImageServingUrl` on the image will therefore be unsuccessful. If a second app needs to serve the image, the app needs to first copy the image and then invoke `getImageServingUrl` on the copy.\n\nTo stop serving the URL,\ncall [CloudStorageTools::deleteImageServingUrl](/appengine/docs/legacy/standard/php/refdocs/classes/google.appengine.api.cloud_storage.CloudStorageTools#method_deleteImageServingUrl).\n| **Note:** If you want to delete the file itself, use the PHP `unlink()` function.\n\nTo use this feature, import the `CloudStorageTools` class: \n\n use google\\appengine\\api\\cloud_storage\\CloudStorageTools;\n\nNow resize and crop the image `image.jpg`: \n\n $options = ['size' =\u003e 400, 'crop' =\u003e true];\n $image_file = \"gs://${my_bucket}/image.jpg\";\n $image_url = CloudStorageTools::getImageServingUrl($image_file, $options);"]]