ImageSource

ImageSource

Class to handle loading various image formats

Constructor

new ImageSource(source, typeopt)

Description:
  • Instantiate an ImageSource

Source:
See:
  • Probe
Example
const personPhoto = new ImageSource('/person/123.jpg', 'url')
Parameters:
Name Type Attributes Default Description
source string

The source of the image data.

type string <optional>
base64

The type of data in the image source, valid values are 'url', 'base64', and 'dataurl'. If not provided 'base64' is the default.

Classes

ImageSource

Methods

(async) data()

Description:
  • Fetch the image data and base64 encode it

Source:
Example
const personPhoto = new ImageSource("/img/photo.jpg")
await personPhoto.data()
console.log(personPhoto.imageData)

(async) toImage()

Description:
  • Create an element, wait for it to load and return it

Source:
Example
// Load the image and draw it on a Canvas
const img = await imgSrc.toImage()
const canvas = document.createElement('canvas')
const ctx = canvas.getContext('2d')
canvas.width = img.width
canvas.height = img.height
ctx.drawImage(img, canvas.width, canvas.height, img.width, img.height)