Fit the background image to canvas size with Fabric js

后端 未结 2 798
时光取名叫无心
时光取名叫无心 2020-12-01 20:08

I am trying to stretch the background image so it can fit the canvas size. But its not working.

I have followed this question and based on comment i have implemente

2条回答
  •  心在旅途
    2020-12-01 20:43

    Hi please update following code.

    img.set({
               width: canvas.getWidth(), 
               height: canvas.getHeight(), 
               originX: 'left', 
               scaleX : canvas.getWidth()/img.width,   //new update
               scaleY: canvas.getHeight()/img.height,   //new update
               originY: 'top'
     });
    

    http://jsfiddle.net/8vLo882n/6/

提交回复
热议问题