Serving Images

The Cloud Storage Tools API provides convenience methods that you can use to serve image files conveniently:

  • 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 publically 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);

Send feedback about...

App Engine standard environment for PHP