Merge pull request #850 from Kienz/patch-1

Fixed `object.toDataURL` if object's originX/originY != 'center'
This commit is contained in:
Juriy Zaytsev 2013-09-15 09:08:49 -07:00
commit fefbc74695

View file

@ -862,23 +862,32 @@
/**
* Converts an object into a data-url-like string
* @param {Object} options Options object
*
* `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
* @param {String} [options.format=png] The format of the output image. Either "jpeg" or "png"
* @param {Number} [options.quality=1] Quality level (0..1). Only used for jpeg.
* @param {Number} [options.multiplier=1] Multiplier to scale by
* @param {Number} [options.left] Cropping left offset
* @param {Number} [options.top] Cropping top offset
* @param {Number} [options.width] Cropping width
* @param {Number} [options.height] Cropping height
* @return {String} Returns a data: URL containing a representation of the object in the format specified by options.format
*/
toDataURL: function(options) {
options || (options = { });
var el = fabric.util.createCanvasElement();
el.width = this.getBoundingRectWidth();
el.height = this.getBoundingRectHeight();
var el = fabric.util.createCanvasElement(),
boundingRect = this.getBoundingRect();
el.width = boundingRect.width;
el.height = boundingRect.height;
fabric.util.wrapElement(el, 'div');
var canvas = new fabric.Canvas(el);
// to avoid common confusion https://github.com/kangax/fabric.js/issues/806
if (options.format === 'jpg') {
options.format = 'jpeg';
}
if (options.format === 'jpeg') {
canvas.backgroundColor = '#fff';
}
@ -889,11 +898,8 @@
top: this.getTop()
};
this.set({
'active': false,
left: el.width / 2,
top: el.height / 2
});
this.set('active', false);
this.setPositionByOrigin(new fabric.Point(el.width / 2, el.height / 2), 'center', 'center');
canvas.add(this);
var data = canvas.toDataURL(options);