Search code examples
fabricjs

How to set repeating background image for a canvas in Fabric JS?


I would like to set an image as the background image for the canvas.

It is possible with the canvas.setBackgroundImage method.

But it is not repeating throughout the background.

How to make it repeatable?

I have seen demos where pattern is used to set repeating background image for text and shapes.

How to use this pattern for canvas background.?


Solution

  • Use canvas.backgroundColor and pattern instead of background image:

    canvas.backgroundColor = new fabric.Pattern({source: image})