Permalink
Browse files

add Context2d#imageSmoothingEnabled=

  • Loading branch information...
1 parent df7a3ad commit d7d4abe2adf5ebee0864445c14e3744706943b1d @tj tj committed Mar 23, 2013
Showing with 29 additions and 5 deletions.
  1. +8 −5 examples/resize.js
  2. +21 −0 lib/context2d.js
View
@@ -15,17 +15,20 @@ img.onerror = function(err){
};
img.onload = function(){
- var width = img.width / 2
- , height = img.height / 2
- , canvas = new Canvas(width, height)
- , ctx = canvas.getContext('2d');
+ var width = 100;
+ var height = 100;
+ var canvas = new Canvas(width, height);
+ var ctx = canvas.getContext('2d');
+
+ ctx.imageSmoothingEnabled = true;
ctx.drawImage(img, 0, 0, width, height);
+
canvas.toBuffer(function(err, buf){
fs.writeFile(__dirname + '/resize.png', buf, function(){
console.log('Resized and saved in %dms', new Date - start);
});
});
};
-img.src = __dirname + '/images/squid.png';
+img.src = process.argv[2] || __dirname + '/images/squid.png';
View
@@ -100,6 +100,27 @@ var parseFont = exports.parseFont = function(str){
};
/**
+ * Enable or disable image smoothing.
+ *
+ * @api public
+ */
+
+Context2d.prototype.__defineSetter__('imageSmoothingEnabled', function(val){
+ this._imageSmoothing = !! val;
+ this.patternQuality = val ? 'best' : 'fast';
+});
+
+/**
+ * Get image smoothing value.
+ *
+ * @api public
+ */
+
+Context2d.prototype.__defineSetter__('imageSmoothingEnabled', function(val){
+ return !! this._imageSmoothing;
+});
+
+/**
* Create a pattern from `Image` or `Canvas`.
*
* @param {Image|Canvas} image

0 comments on commit d7d4abe

Please sign in to comment.