You can resize and crop the image dynamically by specifying the arguments in the URL. The available arguments are:
=sxx
where xx
is an integer from 0–1600 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.=sxx-c
where xx is an integer from 0–1600 representing the cropped image size in pixels, and -c
tells the system to crop the image.# 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
public static String getServingURL(GcsFilename gcsFilename) {
final String bucketName = gcsFilename.getBucketName();
final String objectName = gcsFilename.getObjectName();
final ServingUrlOptions servingUrlOptions =
ServingUrlOptions.Builder.withGoogleStorageFileName("/gs/" + bucketName + "/" + objectName);
return ImagesServiceFactory.getImagesService().getServingUrl(servingUrlOptions);
}