Browse Source

add Context2d#imageSmoothingEnabled=

v1.x
TJ Holowaychuk 12 years ago
parent
commit
d7d4abe2ad
  1. 13
      examples/resize.js
  2. 21
      lib/context2d.js

13
examples/resize.js

@ -15,11 +15,14 @@ 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);
@ -27,5 +30,5 @@ img.onload = function(){
});
};
img.src = __dirname + '/images/squid.png';
img.src = process.argv[2] || __dirname + '/images/squid.png';

21
lib/context2d.js

@ -99,6 +99,27 @@ var parseFont = exports.parseFont = function(str){
return cache[str] = font;
};
/**
* 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`.
*

Loading…
Cancel
Save