Gislef
Gislef

Reputation: 1637

Add Properties in setBackgroundImag and Serialize canvas

I have two doubts:

https://jsfiddle.net/2h5nbrr2/1/

1. How I insert properties in background image:

 function backchange(img)
{ 
 var imag = img.src;  
  canvas.setBackgroundImage(imag, canvas.renderAll.bind(canvas));
}

I trying, but this is not working:

 function backchange(img)
{ 
 var imag = img.src;  
  canvas.setBackgroundImage(imag, canvas.renderAll.bind(canvas)
width: 700,
height: 500,


);
}

2. I not undertand how to apply serialize (json and svg test) for all objects and background, in my example

returns always:

{"objects":[],"background":""}

I am using fabric.js

Thanks for any help

Upvotes: 0

Views: 61

Answers (1)

markE
markE

Reputation: 105015

  1. Your options argument must be an object:

    function backchange(img){ var imag = img.src;
    canvas.setBackgroundImage( imag, canvas.renderAll.bind(canvas). {width: 700,height: 500} ); }

  2. You can use var json=canvas.toJSON ... to serialize most scene elements. As @AndreaBogazzi says, if you want to view the JSON you can: alert(JSON.stringify(json))

Upvotes: 1

Related Questions