APL Image


An Image component draws a bitmap image on the screen. Don't use animated .gif files in your skills. Although these images might appear animated in the simulator, their behavior on screen devices with Alexa might be different.

Properties

The Image component has the following properties in addition to the base component properties. See the meaning of the columns.

The "auto" value isn't supported for dimension-related properties on Image. If you use "auto", the image might not render.

Property Type Default Styled Dynamic Description

align

One of: bottom, bottom-left, bottom-right, center, left, right, top, top-left, top-right

center

Yes

Yes

Alignment of the image within the containing box.

borderRadius

Non-negative Absolute dimension

0

Yes

No

Clipping radius for the image.

filter, filters

Array of filters

[ ]

No

No

Filters to apply to the image.

onFail

Array of commands

[ ]

No

No

Command or commands to run when any source fails to load.

onLoad

Array of commands

[ ]

No

No

Command or commands to run after all sources loaded successfully.

overlayColor

Color

none

Yes

Yes

If set, a theme-appropriate scrim is overlaid on the image. This ensures text placed on the image is legible.

overlayGradient

Gradient

none

Yes

Yes

A colored gradient that overlays the image.

scale

Scale

best-fit

Yes

Yes

How the image will be resized to fit in the bounding box.

source, sources

URL or array of URLs

none

No

Yes

The URL or URLs to download the image from.

All images must specify a width and a height value. To minimize errors, the width and height of an Image component default to 100dp.

The source / sources property of the Image component is an array of one or more image URLs. The Image component doesn't render until after all the URLs in the array have loaded. After all URLs load, the component applies any filters defined in the filters property. When the filters property is empty or not provided, the component renders the last image in the sources array.

Filters modify, augment, and merge images from the image array. The result of filter processing is a single image. The image that results from filter processing can be further modified by the overlayColor and overlayGradient properties.

For details about image filters, see Filters.

When the Image is the source or target of an event, the following values are reported in event.source or event.target:

{
  // Image-specific values
  "type": "Image",
  "url": URL,          // The URL of the image. Contains an array if multiple images are provided

  // General component values
  "bind": Map,         // Access to component data-binding context
  "checked": Boolean,  // Checked state
  "disabled": Boolean, // Disabled state
  "focused": Boolean,  // Focused state
  "height": Number,    // Height of the component, in dp (includes the padding)
  "id": ID,            // ID of the component
  "opacity": Number,   // Opacity of the component [0-1]
  "pressed": Boolean,  // Pressed state
  "uid": UID,          // Runtime-generated unique ID of the component
  "width": Number      // Width of the component, in dp (includes the padding)
}

align

Positions the image within the container.

Name Description

bottom

Align to the bottom and center horizontally

bottom-left

Align the bottom-left corners

bottom-right

Align the bottom-right corners

center

Center horizontally and vertically

left

Align to the left side and center vertically

right

Align to the right side and center vertically

top

Align to the top and center horizontally

top-left

Align the top-left corners

top-right

Align the top-right corners

borderRadius

A uniform clipping radius to be set on the corners of the image. Setting the borderRadius to a large number will create a circular clip.

filter, filters

One or more filtering operations to apply to the image. See Filters.

onFail

Commands to run when any of the requested URLs in sources fails to load. The event contains a single source. If multiple sources fail to load, for example when using a filter, one source triggers the event.

The handler runs one time. After the handler runs, the component is considered invalid. Setting a new value to the sources property can trigger the handler again. The onFail handler runs at most one time for any new sources value.

The onFail handler doesn't affect the display status of the component and the display status doesn't affect the handler. For example, when the display property for the Image component is invisible the component takes up space but doesn't display. The device still attempts to load the image and runs the commands in onFail if the image source fails to load.

The onMount handler for the component runs regardless of whether onFail runs. The onMount handler runs in this scenario because the component can mount and display before or after the component loads the image source.

The onFail handler generates an event with the following form:

"event": {
  "source": {
    "type": "Image",
    "handler": "Fail",
    ...                   // Component source properties
  },
  "value": STRING,        // The url of the image source that failed to load
  "error": STRING,        // The reason of failure
  "errorCode": Number     // Error identifier
}

Refer to Event source for a description of event.source properties.

The onFail event handler runs in fast mode in the component data-binding context.

onLoad

Commands to run after all the requested URLs in sources load.

Setting a new value to the sources property can trigger the handler to run again. The onLoad handler runs at most one time for any new 'sources' value.

The onLoad handler doesn't affect the display status of the component and the display status doesn't affect the handler. For example, when the display property for the Image component is invisible the component takes up space but doesn't display. The device still attempts to load the image and runs the commands in onLoad after the image source loads.

The onMount handler for the component runs regardless of whether onLoad runs. The Image component can mount and display before or after the component loads the image source.

The onLoad handler generates an event with the following form:

"event": {
    "source": {
        "type": "Image",
        "handler": "Load",
        ...                   // Component source properties
    }
}

Refer to Event source for a description of event.source properties.

The onLoad event handler runs in fast mode in the component data-binding context.

overlayColor

A color applied as a scrim across the image. The color must have a transparent component for the image to show. For instance, you could set overlayColor to rgba(white,0.3) to overlay the image with white at 30% opacity.

Note that overlayColor is a convenience name for a filter that overlays the image with a single color. The overlayColor filter is applied after any filters defined by the filter property.

The scrim applies only to the drawn area of the image, not the padding or any blank space left over after image scaling and alignment.

overlayGradient

A gradient applied as a scrim across the image. The gradient must have a transparent component for the image to show. An overlayGradient is equivalent to a filter that overlays the image with a named gradient. The overlayGradient filter is applied after any filters defined by the filter property and after the overlayColor property.

The gradient applies only to the drawn area of the image, not the padding or any blank space left over after image scaling and alignment.

scale

Scales the image within the container.

Name Description

none

Doesn't scale the image. The align property positions the image in the bounding box. The portions of the image that fall outside of the bounding box are clipped.

fill

Scales the image non-uniformly so that the width matches the bounding box width and the height matches the bounding box height.

best-fill

Scales the image uniformly up or down so that the bounding box is completely covered. The align property positions the scaled image within the bounding box.

best-fit

Scales the image uniformly up or down so that the entire image fits within the bounding box. The align property positions the scaled image within the bounding box.

best-fit-down

Scales the image uniformly as per best-fit, but only allow down-scaling, never up-scaling. This ensures that the image doesn't appear pixelated.

The following example illustrates the scale options with different images. The Frame defines a box with a green border. The Image component displays inside the Frame and uses the height and width of the Frame to define the bounding box. Click the Change Scale button to cycle through each of the scale options. Click the Change Image button to view different images fit within the same bounding box.


source, sources

The URL of the image to download and display.

Use https instead of http for image source URLs. Many Alexa devices don't support the http scheme in skill APL documents for security reasons.

You can set this property to an array of URLs instead of a single string. When the filters property is empty, the component displays the last image in the array. When the filters property contains one or more filters, the filter determines which image or images to use in the array. For details about filters, see Filters.

Manage alignment, scaling, and sizing of images

Image alignment and scaling can be complex. Images must have a specified height and width. The actual image must then be clipped, scaled, and positioned within the bounding box of the Image component.

The scale mode controls how the image size is adjusted to fit the bounding box.

The align mode controls how the image (after scaling) is positioned in the box.

Any clipping is always applied to the bounding box, not to the scaled image.

Sample image

The following example shows an Image component. The bounding box for the Image is 300 x 300 pixels. The large value for borderRadius clips the image to a circle.

In this case, the image fills a 300x300 box on the screen.



Was this page helpful?

Last updated: Feb 29, 2024