Notice: Over the next few months, we're reorganizing the App Engine documentation site to make it easier to find content and better align with the rest of Google Cloud products. The same content will be available, but the navigation will now match the rest of the Cloud products. If you have feedback or questions as you navigate the site, click Send Feedback.

As PHP version 5.5 is no longer supported by the community, we strongly recommend new apps use the PHP 7+ runtime.

Serving Images

The App Engine API for Cloud Storage Tools provides convenience methods for serving image files:

  • CloudStorageTools.getImageServingUrl()
  • CloudStorageTools.deleteImageServingUrl()

One advantage of using this method to serve images over simply making the files public is the ability to resize and crop dynamically, without needing to store the images in different sizes.

CloudStorageTools::getImageServingUrl returns a serving URL for an image. If the image will be displayed within an HTTPS page, set secure_url to True to avoid mixed-content warnings.

Notice that this URL is publicly readable by everyone, but it is not "guessable".

To stop serving the URL, call CloudStorageTools::deleteImageServingUrl.

To use this feature, import the CloudStorageTools class:

use google\appengine\api\cloud_storage\CloudStorageTools;

Now resize and crop the image image.jpg:

$options = ['size' => 400, 'crop' => true];
$image_file = "gs://${my_bucket}/image.jpg";
$image_url = CloudStorageTools::getImageServingUrl($image_file, $options);