Add support for same options in fabric.Object#toDataURL as there are in fabric.Canvas#toDataURL. Closes #609

This commit is contained in:
kangax 2013-05-06 11:52:05 -04:00
parent 662b322cd1
commit a47128afa4
5 changed files with 25 additions and 5 deletions

10
dist/all.js vendored
View file

@ -10388,9 +10388,15 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Converts an object into a data-url-like string
* @param {Object} options
*
* `format` the format of the output image. Either "jpeg" or "png".
* `quality` quality level (0..1)
* `multiplier` multiplier to scale by {Number}
*
* @return {String} data url representing an image of this object
*/
toDataURL: function() {
toDataURL: function(options) {
var el = fabric.util.createCanvasElement();
el.width = this.getBoundingRectWidth();
el.height = this.getBoundingRectHeight();
@ -10414,7 +10420,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
});
canvas.add(this);
var data = canvas.toDataURL();
var data = canvas.toDataURL(options);
this.set(origParams).setCoords();

2
dist/all.min.js vendored

File diff suppressed because one or more lines are too long

BIN
dist/all.min.js.gz vendored

Binary file not shown.

View file

@ -739,9 +739,15 @@
/**
* Converts an object into a data-url-like string
* @param {Object} options
*
* `format` the format of the output image. Either "jpeg" or "png".
* `quality` quality level (0..1)
* `multiplier` multiplier to scale by {Number}
*
* @return {String} data url representing an image of this object
*/
toDataURL: function() {
toDataURL: function(options) {
var el = fabric.util.createCanvasElement();
el.width = this.getBoundingRectWidth();
el.height = this.getBoundingRectHeight();
@ -765,7 +771,7 @@
});
canvas.add(this);
var data = canvas.toDataURL();
var data = canvas.toDataURL(options);
this.set(origParams).setCoords();

View file

@ -457,6 +457,14 @@
var dataURL = cObj.toDataURL();
equal(typeof dataURL, 'string');
equal(dataURL.substring(0, 21), 'data:image/png;base64');
try {
cObj.toDataURL({ format: 'jpeg' });
equal(dataURL.substring(0, 22), 'data:image/jpeg;base64');
}
catch(err) {
fabric.log('jpeg toDataURL not supported');
}
}
});