Jon Blake
Jon Blake

Reputation: 11

Fabricjs v6+ load background image

Has anyone had experience with tbe new fabricjs version 6. In particular loading a background image. I am using version 6.2.it seems the documentation is still a mix of the v5 code plus v6. Certainly all the examples were based on v5

Implemented the upgrade and migration guide to version 6.Expected same behaviour.

Upvotes: 1

Views: 529

Answers (1)

Alruna L
Alruna L

Reputation: 114

import * as fabric from 'fabric'

const imageUrl = 'https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png'
const image = new Image()
image.src = imageUrl

let canvas

image.onload = () => {
  const ele = document.getElementById('dom')
  canvas = new fabric.Canvas(ele, {
    width: 300,
    height: 200,
    backgroundImage: new fabric.FabricImage(image)
  })
  canvas.renderAll()
}
<canvas id="dom"></canvas>

Upvotes: 1

Related Questions