Alias "jpg" format to "jpeg". Closes #806

This commit is contained in:
kangax 2013-09-14 18:44:44 +02:00
parent 7d56197f78
commit 408a8b9de6
6 changed files with 90 additions and 55 deletions

59
dist/all.js vendored
View file

@ -9931,6 +9931,11 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
var canvasEl = this.upperCanvasEl || this.lowerCanvasEl;
var croppedCanvasEl = this.__getCroppedCanvas(canvasEl, cropping);
// to avoid common confusion https://github.com/kangax/fabric.js/issues/806
if (format === 'jpg') {
format = 'jpeg';
}
var data = (fabric.StaticCanvas.supports('toDataURLWithQuality'))
? (croppedCanvasEl || canvasEl).toDataURL('image/' + format, quality)
: (croppedCanvasEl || canvasEl).toDataURL('image/' + format);
@ -10896,7 +10901,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Basic getter
* @param {String} property
* @param {String} property Property name
* @return {Any} value of a property
*/
get: function(property) {
@ -10905,8 +10910,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Sets property to a given value. When changing position/dimension -related properties (left, top, scale, angle, etc.) `set` does not update position of object's borders/controls. If you need to update those, call `setCoords()`.
* @param {String|Object} key (if object, iterate over the object properties)
* @param {Object|Function} value (if function, the value is passed into it and its return value is used as a new one)
* @param {String|Object} key Property name or object (if object, iterate over the object properties)
* @param {Object|Function} value Property value (if function, the value is passed into it and its return value is used as a new one)
* @return {fabric.Object} thisArg
* @chainable
*/
@ -10961,7 +10966,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Toggles specified property from `true` to `false` or from `false` to `true`
* @param {String} property property to toggle
* @param {String} property Property to toggle
* @return {fabric.Object} thisArg
* @chainable
*/
@ -10986,7 +10991,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Renders an object on a specified context
* @param {CanvasRenderingContext2D} ctx context to render on
* @param {CanvasRenderingContext2D} ctx Context to render on
* @param {Boolean} [noTransform] When true, context is not transformed
*/
render: function(ctx, noTransform) {
@ -11192,7 +11197,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Returns true if specified type is identical to the type of an instance
* @param type {String} type to check against
* @param type {String} type Type to check against
* @return {Boolean}
*/
isType: function(type) {
@ -11234,6 +11239,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
* <b>Backwards incompatibility note:</b> This method was named "setGradientFill" until v1.1.0
* @param {String} property Property name 'stroke' or 'fill'
* @param {Object} [options] Options object
* @chainable
*/
setGradient: function(property, options) {
options || (options = { });
@ -11258,7 +11264,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
gradient.colorStops.push({offset: position, color: color.toRgb(), opacity: color.getAlpha()});
}
this.set(property, fabric.Gradient.forObject(this, gradient));
return this.set(property, fabric.Gradient.forObject(this, gradient));
},
/**
@ -11281,10 +11287,22 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
return this.set('shadow', new fabric.Shadow(options));
},
/**
* Sets "color" of an instance (alias of `set('fill', &hellip;)`)
* @param {String} color Color value
* @return {fabric.Text} thisArg
* @chainable
*/
setColor: function(color) {
this.set('fill', color);
return this;
},
/**
* Centers object horizontally on canvas to which it was added last.
* You might need to call `setCoords` on an object after centering, to update controls area.
* @return {fabric.Object} thisArg
* @chainable
*/
centerH: function () {
this.canvas.centerObjectH(this);
@ -11439,8 +11457,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Translates the coordinates from origin to center coordinates (based on the object's dimensions)
* @param {fabric.Point} point The point which corresponds to the originX and originY params
* @param {string} enum('left', 'center', 'right') Horizontal origin
* @param {string} enum('top', 'center', 'bottom') Vertical origin
* @param {String} originX Horizontal origin: 'left', 'center' or 'right'
* @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
* @return {fabric.Point}
*/
translateToCenterPoint: function(point, originX, originY) {
@ -11467,8 +11485,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Translates the coordinates from center to origin coordinates (based on the object's dimensions)
* @param {fabric.Point} point The point which corresponds to center of the object
* @param {string} enum('left', 'center', 'right') Horizontal origin
* @param {string} enum('top', 'center', 'bottom') Vertical origin
* @param {String} originX Horizontal origin: 'left', 'center' or 'right'
* @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
* @return {fabric.Point}
*/
translateToOriginPoint: function(center, originX, originY) {
@ -11512,8 +11530,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Returns the coordinates of the object as if it has a different origin
* @param {string} enum('left', 'center', 'right') Horizontal origin
* @param {string} enum('top', 'center', 'bottom') Vertical origin
* @param {String} originX Horizontal origin: 'left', 'center' or 'right'
* @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
* @return {fabric.Point}
*/
// getPointByOrigin: function(originX, originY) {
@ -11572,8 +11590,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Sets the position of the object taking into consideration the object's origin
* @param {fabric.Point} point The new position of the object
* @param {string} enum('left', 'center', 'right') Horizontal origin
* @param {string} enum('top', 'center', 'bottom') Vertical origin
* @param {String} originX Horizontal origin: 'left', 'center' or 'right'
* @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
* @return {void}
*/
setPositionByOrigin: function(pos, originX, originY) {
@ -18125,17 +18143,6 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
},
/* _TO_SVG_END_ */
/**
* Sets "color" of an instance (alias of `set('fill', &hellip;)`)
* @param {String} value
* @return {fabric.Text} thisArg
* @chainable
*/
setColor: function(value) {
this.set('fill', value);
return this;
},
/**
* Sets specified property to a specified value
* @param {String} key

6
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.

59
dist/all.require.js vendored
View file

@ -9931,6 +9931,11 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
var canvasEl = this.upperCanvasEl || this.lowerCanvasEl;
var croppedCanvasEl = this.__getCroppedCanvas(canvasEl, cropping);
// to avoid common confusion https://github.com/kangax/fabric.js/issues/806
if (format === 'jpg') {
format = 'jpeg';
}
var data = (fabric.StaticCanvas.supports('toDataURLWithQuality'))
? (croppedCanvasEl || canvasEl).toDataURL('image/' + format, quality)
: (croppedCanvasEl || canvasEl).toDataURL('image/' + format);
@ -10896,7 +10901,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Basic getter
* @param {String} property
* @param {String} property Property name
* @return {Any} value of a property
*/
get: function(property) {
@ -10905,8 +10910,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Sets property to a given value. When changing position/dimension -related properties (left, top, scale, angle, etc.) `set` does not update position of object's borders/controls. If you need to update those, call `setCoords()`.
* @param {String|Object} key (if object, iterate over the object properties)
* @param {Object|Function} value (if function, the value is passed into it and its return value is used as a new one)
* @param {String|Object} key Property name or object (if object, iterate over the object properties)
* @param {Object|Function} value Property value (if function, the value is passed into it and its return value is used as a new one)
* @return {fabric.Object} thisArg
* @chainable
*/
@ -10961,7 +10966,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Toggles specified property from `true` to `false` or from `false` to `true`
* @param {String} property property to toggle
* @param {String} property Property to toggle
* @return {fabric.Object} thisArg
* @chainable
*/
@ -10986,7 +10991,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Renders an object on a specified context
* @param {CanvasRenderingContext2D} ctx context to render on
* @param {CanvasRenderingContext2D} ctx Context to render on
* @param {Boolean} [noTransform] When true, context is not transformed
*/
render: function(ctx, noTransform) {
@ -11192,7 +11197,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Returns true if specified type is identical to the type of an instance
* @param type {String} type to check against
* @param type {String} type Type to check against
* @return {Boolean}
*/
isType: function(type) {
@ -11234,6 +11239,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
* <b>Backwards incompatibility note:</b> This method was named "setGradientFill" until v1.1.0
* @param {String} property Property name 'stroke' or 'fill'
* @param {Object} [options] Options object
* @chainable
*/
setGradient: function(property, options) {
options || (options = { });
@ -11258,7 +11264,7 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
gradient.colorStops.push({offset: position, color: color.toRgb(), opacity: color.getAlpha()});
}
this.set(property, fabric.Gradient.forObject(this, gradient));
return this.set(property, fabric.Gradient.forObject(this, gradient));
},
/**
@ -11281,10 +11287,22 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
return this.set('shadow', new fabric.Shadow(options));
},
/**
* Sets "color" of an instance (alias of `set('fill', &hellip;)`)
* @param {String} color Color value
* @return {fabric.Text} thisArg
* @chainable
*/
setColor: function(color) {
this.set('fill', color);
return this;
},
/**
* Centers object horizontally on canvas to which it was added last.
* You might need to call `setCoords` on an object after centering, to update controls area.
* @return {fabric.Object} thisArg
* @chainable
*/
centerH: function () {
this.canvas.centerObjectH(this);
@ -11439,8 +11457,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Translates the coordinates from origin to center coordinates (based on the object's dimensions)
* @param {fabric.Point} point The point which corresponds to the originX and originY params
* @param {string} enum('left', 'center', 'right') Horizontal origin
* @param {string} enum('top', 'center', 'bottom') Vertical origin
* @param {String} originX Horizontal origin: 'left', 'center' or 'right'
* @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
* @return {fabric.Point}
*/
translateToCenterPoint: function(point, originX, originY) {
@ -11467,8 +11485,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Translates the coordinates from center to origin coordinates (based on the object's dimensions)
* @param {fabric.Point} point The point which corresponds to center of the object
* @param {string} enum('left', 'center', 'right') Horizontal origin
* @param {string} enum('top', 'center', 'bottom') Vertical origin
* @param {String} originX Horizontal origin: 'left', 'center' or 'right'
* @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
* @return {fabric.Point}
*/
translateToOriginPoint: function(center, originX, originY) {
@ -11512,8 +11530,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Returns the coordinates of the object as if it has a different origin
* @param {string} enum('left', 'center', 'right') Horizontal origin
* @param {string} enum('top', 'center', 'bottom') Vertical origin
* @param {String} originX Horizontal origin: 'left', 'center' or 'right'
* @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
* @return {fabric.Point}
*/
// getPointByOrigin: function(originX, originY) {
@ -11572,8 +11590,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
/**
* Sets the position of the object taking into consideration the object's origin
* @param {fabric.Point} point The new position of the object
* @param {string} enum('left', 'center', 'right') Horizontal origin
* @param {string} enum('top', 'center', 'bottom') Vertical origin
* @param {String} originX Horizontal origin: 'left', 'center' or 'right'
* @param {String} originY Vertical origin: 'top', 'center' or 'bottom'
* @return {void}
*/
setPositionByOrigin: function(pos, originX, originY) {
@ -18125,17 +18143,6 @@ fabric.Image.filters.BaseFilter = fabric.util.createClass(/** @lends fabric.Imag
},
/* _TO_SVG_END_ */
/**
* Sets "color" of an instance (alias of `set('fill', &hellip;)`)
* @param {String} value
* @return {fabric.Text} thisArg
* @chainable
*/
setColor: function(value) {
this.set('fill', value);
return this;
},
/**
* Sets specified property to a specified value
* @param {String} key

View file

@ -45,6 +45,11 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati
var canvasEl = this.upperCanvasEl || this.lowerCanvasEl;
var croppedCanvasEl = this.__getCroppedCanvas(canvasEl, cropping);
// to avoid common confusion https://github.com/kangax/fabric.js/issues/806
if (format === 'jpg') {
format = 'jpeg';
}
var data = (fabric.StaticCanvas.supports('toDataURLWithQuality'))
? (croppedCanvasEl || canvasEl).toDataURL('image/' + format, quality)
: (croppedCanvasEl || canvasEl).toDataURL('image/' + format);

View file

@ -221,6 +221,22 @@
}
});
test('toDataURL jpg', function() {
if (!fabric.Canvas.supports('toDataURL')) {
alert("toDataURL is not supported by this environment. Some of the tests can not be run.");
}
else {
try {
var dataURL = canvas.toDataURL({ format: 'jpg' });
equal(dataURL.substring(0, 22), 'data:image/jpeg;base64');
}
// node-canvas does not support jpeg data urls
catch(err) {
ok(true);
}
}
});
test('centerObjectH', function() {
ok(typeof canvas.centerObjectH == 'function');
var rect = makeRect({ left: 102, top: 202 });