I am building a firefox plugin which allows users to draw any arbitrary figure on an object and save it as an image (png file).
var $ = getJQueryOb();
var canvas = '<canvas id="canvas" width="1024" height="1024" style="position:absolute; top:0px; left:0px;"></canvas>';
var currentWindow = Components.classes["@mozilla.org/appshell/window-mediator;1"].getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow("navigator:browser");
var mainDoc = currentWindow.getBrowser().contentDocument;
var cObj = $(canvas).appendTo(mainDoc.body);
$(cObj).bind('mousemove', handlePenDraw);
Using this I can draw on the canvas. However, when I save the image, I do not want the full canvas to be saved - rather just the 'bounding rectangle' around the image that was created to be saved.
Is there any way I can acheive this. What I am currently doing is going to save the canvas as it is:
var $ = getJQueryOb();
var canvas = $('#canvas')[0];
var dURL = canvas.toDataURL("image/png");
saveToFile(dURL, "image-file.png");