Skip to content
On this page

Image Shape

TIP

This class is a descendant of Shape it also inherits all the options that Shape provides.

TIP

This component also supports a return function

To create an image with fcanvas, we can instantiate a Image object with image property.

For image property you can use:

image An element to draw into the context. The specification permits any canvas image source, specifically,

In addition, this shape also provides a few other parameters:

Require Options

NameTypeDescription
imageMayBeRef<CanvasImageSource | string>multiply by a value as stated above

Inherit Shape

NameTypeDescription
xMayBeRef<number>offset x
yMayBeRef<number>offset y

Optional Options

NameTypeDefaultDescription
cropMayBeRef<{ x: number; y: number; width: number; height: number }>undefinedAn object that specifies the x, y coordinates to start cropping and the width, height dimensions of the image to be crop.
widthMayBeRef<number>width of image or crop.width if availableFinal width to display photo
heightMayBeRef<number>height of image or crop.height if availableFinal height to display photo

TIP

The crop feature provided by this component is very simple. If you need more powerful cropping (e.g. Tile) use cropImage

Demo

ts
import { Stage, Layer, Image, loadImage } from "fcanvas"

const stage = new Stage().mount("#app")
const layer = new Layer().addTo(stage)

const image = new Image({
  x: 0,
  y: 0,
  width: 150,
  height: 150,
  image: await loadImage("https://shin.is-a.dev/favicon.ico")
}).addTo(layer)

Released under the MIT License.