Search code examples
canvasbackgroundpositionfabricjs

Fabricjs background position


i need somehow to change background image position if image already assigned to background! It's possible? I don't find any information how i can change position/size of current background in fabricjs. Thanks in advance for your help!

  imOb.onload = function () {
                        var dcrIm = 1200 / $("canvas").width();
                        var image = new fabric.Image(imOb, {
                            width: imOb.width / decr,
                            height: imOb.height / decr
                        });


                            fCanvas.setBackgroundImage(image, fCanvas.renderAll.bind(fCanvas), {
                                originX: 'left',
                                originY: 'top',
                                left: 0,
                                top: 0
                            });


                    }

Solution

  • Hope this is right answer – I am positioning my bgImage like this:

    canvas.setBackgroundColor({
                        source: YourFilepath,
                        repeat: 'no-repeat'
                    }, canvas.renderAll.bind(canvas));
    

    Where "repeat:" will accept "repeat" "no-repeat" "repat-x" and "repeat-y". Otherwise I think that stuff like "originX" and width/height should be also working for the image you are creating.