Using Image Sizes

After you create image size objects as described in Creating Image Sizes, you can use the ImageSize class to retrieve URLs for delivering the images to clients.

Retrieving an Image Editing URL

The snippet Listing Image Sizes by Display Name instantiates an image size with dimensions 150 × 100. You can use the method get to retrieve the image-editing URL.

Map<String,String> imageSizeMap = imageSize.toAttributes(image);
String imageEditingUrl = imageSizeMap.get(SRC_ATTRIBUTE);

In the previous snippet—

  • Line 1 instantiates a map of image attributes to be applied to a specific StorageItem image.
  • Line 2 retrieves a string that includes the location of the image editor, various image editing commands, and the encoded URL for the image on your Brightspot server. The resulting image-editing URL is similar to the following.!/?

In the previous URL, the dimensions for the resize are the same as those specified in the snippet Listing Image Sizes by Display Name.

At run time, Brightspot checks if a cached version of the edited image is available; if not, it sends the image along with the editing commands to the DIMS server, caches the result, and sends the resulting image to the client.

For an explanation of an image-editing URL, see Image URLs.

Retrieving an Image’s URL

Brightspot saves images (and other types of files) as StorageItems, automatically associating a publicly facing URL to the image. You can use the static convenience method ImageSize.getUrl to retrieve the URL.

String myUrl = ImageSize.getUrl(image);

The previous snippet retrieves the publicly facing URL for the image stored on your Brightspot server, similar to the following.

See also: