KineticJS icon indicating copy to clipboard operation
KineticJS copied to clipboard

Using stage.toDataUrl ,Shape function() drawFunc content will not captured

Open 05bca054 opened this issue 12 years ago • 1 comments

Hello,

I recently found using stage.toDataURL for saving stage content as a image.(KineticJS version 5.0.1)

Custom Shape drawFunc content with core HTML5 canvas object will not applied in image after saving an image.

###################### Images

Please see attached image to get better clarity.

1)Original canvas(stage). 192 168 1 10 naitik rosets rogets_od html 1

2)Image after saving stage content test1

We see that the vertical string "Sample Text" will not saved or it's invisible whatever it is.

###################### Code

1)Here is my code for shape where i print vertical string "Sample Text"

var sampleText = new Kinetic.Shape({
drawFunc: function(context) { var ctx=this.getContext()._context; ctx.beginPath();
var maxWidth = 2; var lineHeight = 25; var x = 415; var y = 700; var text = 'Sample Text'; ctx.font = '15pt Calibri'; ctx.fillStyle = 'green'; //Function for vetical text display wrapText(ctx, text, x, y, maxWidth, lineHeight); ctx.closePath(); ctx.fill(); ctx.restore();
},
});

//wrapText function if needed function wrapText(context, text, x, y, maxWidth, lineHeight) { var words = text.split(''); var line = ''; //alert(context); for(var n = 0; n < words.length; n++) { var testLine = line + words[n] + ' '; var metrics = context.measureText(testLine); var testWidth = 20; if (testWidth > maxWidth && n > 0) { context.fillText(line, x, y); line = words[n] + ' '; y += lineHeight; } else { line = testLine; } } context.fillText(line, x, y); }

2)Stage code for saving an image

stage.toDataURL({ callback: function(dataUrl) { /* * here you can do anything you like with the data url. * In this tutorial we'll just open the url with the browser * so that you can see the result as an image */ $('#theimage').attr('src',dataUrl); $.ajax({ type: "POST", url: "save.php", data: { imageData: dataUrl }, }); } });

Please advise.

Thanks in advance for your time and consideration.

-Naitik.

05bca054 avatar Mar 01 '14 06:03 05bca054

The answer on stackoverflow: http://stackoverflow.com/a/22140094/512042. I will close the issue.

lavrton avatar Mar 03 '14 06:03 lavrton