You are currently viewing the Homey Apps SDK v2 documentation. New apps should use Homey Apps SDK v3 ››

Homey.Image

const { Image } = require('homey');

The Image class can be used to create an Image, which can be used in the Flow Editor. An image must be registered, and the contents will be retrieved when needed.

Table of Contents

Constructor

new Homey.Image()

Properties:
Name Type Description
cloudUrl string

The public URL to this image using Athom's cloud proxy (HTTPS)

localUrl string

The public URL to this image using Homey's local IP address (HTTP)

Methods

getBuffer(callback) → {Promise}

Get the Buffer

Deprecated:
Parameters:
Name Type Description
callback function
Name Type Description
err Error
data Buffer
Returns:
Type:
Promise

getFormat() → {String}

Get the format

Deprecated:
Returns:
Type:
String

format Either png, jpg or gif

(async) getStream() → {Readable}

Returns a stream containing the image data.

Since:
  • 2.2.0
Returns:
Type:
Readable

A nodejs stream containing the image data. The readable stream contains metadata properties (Image#ImageStreamMetadata)

(async) pipe(target) → {Image#ImageStreamMetadata}

Pipe the image into the target stream and returns metadata.

Since:
  • 2.2.0
Parameters:
Name Type Description
target WritableStream
Returns:
Type:
Image#ImageStreamMetadata

Stream metadata

register(callbackopt) → {Promise}

Register the image. This is a shorthand method for ManagerImages#registerImage.

Parameters:
Name Type Attributes Description
callback function <optional>
Name Type Description
err Error
image Image
Returns:
Type:
Promise

setBuffer(source)

Set the image's data

Deprecated:
Parameters:
Name Type Description
source Buffer | function

A buffer of the image, or a Function. When provided a function, this will be called with parameters (args, callback) when someone requests the buffer. This is mostly useful for external image sources.

setPath(path)

Set the image's path

Parameters:
Name Type Description
path String

Relative path to your image, e.g. /userdata/kitten.jpg

setStream(source)

Set the image's data.

Since:
  • 2.2.0
Library:
Parameters:
Name Type Description
source function

This function will be called with the parameter (stream) when someone pipes this image. Pipe the image content to the stream. This is mostly useful for external image sources.

setUrl(url)

Set the image's URL. This URL must be accessible from any network.

Parameters:
Name Type Description
url String

Absolute url, https://

unregister(callbackopt) → {Promise}

Unregister the image. This is a shorthand method for ManagerImages#unregisterImage.

Parameters:
Name Type Attributes Description
callback genericCallbackFunction <optional>
Returns:
Type:
Promise

update(callback) → {Promise}

Notify that the image's contents have changed

Parameters:
Name Type Description
callback
Name Type Description
err Error
Returns:
Type:
Promise

Type Definitions

ImageStreamMetadata

Properties:
Name Type Attributes Description
filename string

A filename for this image

contentType string

The mime type of this image

contentLength number <optional>

The size in bytes, if available