Using stage.toDataUrl ,Shape function() drawFunc content will not captured
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).

2)Image after saving stage content

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.
The answer on stackoverflow: http://stackoverflow.com/a/22140094/512042. I will close the issue.