Example #1
0
  'test Context2d#lineJoin=': function(){
    var canvas = new Canvas(200, 200)
      , ctx = canvas.getContext('2d');

    assert.equal('miter', ctx.lineJoin);
    ctx.lineJoin = 'round';
    assert.equal('round', ctx.lineJoin);
  },
Example #2
0
  'test Context2d#lineCap=': function(){
    var canvas = new Canvas(200, 200)
      , ctx = canvas.getContext('2d');

    assert.equal('butt', ctx.lineCap);
    ctx.lineCap = 'round';
    assert.equal('round', ctx.lineCap);
  },
Example #3
0
 'test Context2d#font=': function(){
   var canvas = new Canvas(200, 200)
     , ctx = canvas.getContext('2d');
   
   assert.equal('10px sans-serif', ctx.font);
   ctx.font = '15px Arial, sans-serif';
   assert.equal('15px Arial, sans-serif', ctx.font);
 },
Example #4
0
Tile.prototype.drawGeojson = function(points, settings, next) {
  if(typeof settings === 'function') {
    next = settings
  }
  var tile_canvas = new canvas(this.map.tile_size, this.map.tile_size)
    , ctx = tile_canvas.getContext('2d')
    , drawn = 0
    , self = this
  
  
  for(var i in settings) { ctx[i] = settings[i] }
  
  if(!points || points.length === 0) {
    return next(tile_canvas.toBuffer())
  }

  var drawFeature = function(feature, next) {
    switch(feature.type){
      case "Point":
        var offset = self.getOffset(feature.coordinates)
        ctx.beginPath()
        ctx.arc(offset[0], offset[1], 1, 0, Math.PI * 2, true)
        ctx.closePath()
        ctx.fill()
        next()
        break 
      case "Polygon":
        self.simplifyPoly(feature, function(processedFeature){
          ctx.beginPath()
          for(var a = 0; a < processedFeature.coordinates.length; a++) {
            if(a === 0) { // First ring, clockwise.
              for(var b = 0; b < processedFeature.coordinates[a].length; b++){
                var offset = self.getOffset(processedFeature.coordinates[a][b])
                b === 0 ? ctx.moveTo(offset[0], offset[1]) : ctx.lineTo(offset[0], offset[1])
              }
            } else { // Holes counter-clockwise
              for (var b = processedFeature.coordinates[a].length - 1; b >= 0; b--) {
                var offset = self.getOffset(processedFeature.coordinates[a][b])
                b === 0 ? ctx.moveTo(offset[0], offset[1]) : ctx.lineTo(offset[0], offset[1])
              }
            }
            ctx.closePath();
          }
          ctx.fill()
          next()
        })
        break
    }
  }

  for(var i in points) {
    drawFeature(points[i], function(){
      if(++drawn === points.length) {
       return next(tile_canvas.toBuffer())
      }
    })
  }
}
function mapToCanvas( mapData, xCenter, yCenter, width, height, scale ) {

  var halfWidth = width/(2*scale), halfHeight = height/(2*scale);
  var validObjects = getMapObjectsInBounds( mapData.objects, xCenter - halfWidth, yCenter - halfHeight, xCenter + halfWidth, yCenter + halfHeight, 16 / scale );

  // initialize our canvas
  var canvas = new Canvas( width, height );
  var ctx = canvas.getContext( "2d" );
  ctx.antialias = "none";

  ctx.scale( scale, scale );
  ctx.translate( -xCenter, -yCenter );
  
  // fill the background with the sky color
  ctx.fillStyle = mapData.skyColor.toString() || "#000000";
  ctx.fillRect( xCenter - ( width / scale )/2, yCenter - ( height / scale)/2, width / scale * 2, height / scale * 2 );

  var spriteBuffers = {};

  // draw the sprites to the canvas
  return Promise.all( validObjects.map( function( objDef ) {
    var filename = getObjSpritePath( objDef );

    // use a promise to fetch the sprite data
    return new Promise( function( ok, fail ) {
      if ( spriteBuffers[ filename ] ) {
        ok( spriteBuffers[ filename ] );
      } else {
        fs.readFile( filename, function( err, spriteBuffer ) {
          if ( err ) fail( err );

          spriteBuffers[ filename ] = spriteBuffer;
          ok( spriteBuffer );
        })
      }
    })
    .then( function( spriteBuffer ) {
      let imageBuffer = new Image();
      imageBuffer.src = spriteBuffer;

      // set up transformation matrix
      ctx.save();
      ctx.translate( objDef.x + halfWidth, objDef.y + halfHeight );
      if ( objDef.r ) ctx.rotate( objDef.r * Math.PI / 180 );

      // draw it!!!
      ctx.drawImage( imageBuffer, -16, -16, 32, 32 );

      // restore the canvas
      ctx.restore();
    });

  })) // END validObjects.map
  .then( function() {
    return canvas;
  });

}
Example #6
0
exports.ilbm_canvas = function(file, options) {
	if(file.type !== 'ILBM') {
		throw "Only IFF-ILBM files supported, "+file.type+" given";
	}
	var root = file.content;
    options = options || {};
	if(!options.colorMap) {
		options.colorMap = root.chunkById('CMAP');
	}
	var properties = root.chunkById('BMHD');
	var body = root.chunkById('BODY');
	var Canvas = require('canvas');
	var canvas = new Canvas(properties.width, properties.height);
	var ctx = canvas.getContext('2d');
	var im = ctx.createImageData(properties.width, properties.height);

	var transparentPlane = properties.masking === 'mskHasMask' ? properties.planes - 1 : null;
	var transparentColor = properties.masking === 'mskHasTransparentColor' ? properties.transparentColor : null;

	//Planes are channels, just strangely named…
	var expectedBytesPerRow = properties.width/8;
	var bufferprops = {buffer: body.ckData, offset: 0};
	var counter = 0;
	for(var line=0;line<properties.height;line++) {
		var planes = [];
		for(var row=0;row<properties.planes;row++) {
			planes.push(exports.unpack(bufferprops, properties.compression, expectedBytesPerRow));
		}
		planes.reverse();
		for(var col=0;col<properties.width;col++) {
			//get the bits from each plane
			byteNumber = Math.floor(col/8);
			bitNumber = 7 - col%8;
			colorNumber = 0;
			isTransparent = false;
			var lastPlane = planes.length - 1;
			planes.forEach(function(plane, count) {
				var bit = plane.readUInt8(byteNumber);
				bit = (bit >> bitNumber) & 0x01;
				if(count === transparentPlane) {
					isTransparent = !bit;
				} else {
					colorNumber = (colorNumber << 1) | bit;
				}
			});
			if(!options.killTransparency && transparentColor) {
				isTransparent = colorNumber === transparentColor;
			}
			var color = options.colorMap.colors[colorNumber];
			im.data[counter++] = color.red;
			im.data[counter++] = color.green;
			im.data[counter++] = color.blue;
			im.data[counter++] = isTransparent ? 0 : 255;
		}
	}
	ctx.putImageData(im, 0, 0);
	return canvas;
};
Example #7
0
 create: function NodeCanvasFactory_create(width, height) {
   assert(width > 0 && height > 0, 'Invalid canvas size');
   var canvas = new Canvas(width, height);
   var context = canvas.getContext('2d');
   return {
     canvas: canvas,
     context: context,
   };
 },
Example #8
0
 'test Context2d#createImageData(ImageData)': function(assert){
   var canvas = new Canvas(20, 20)
     , ctx = canvas.getContext('2d');
   
   var imageData = ctx.createImageData(ctx.createImageData(2, 6));
   assert.equal(2, imageData.width);
   assert.equal(6, imageData.height);
   assert.equal(2 * 6 * 4, imageData.data.length);
 },
Example #9
0
    resize: function (width, height) {
        var canvas = new Canvas(width, height),
            ctx = canvas.getContext('2d');

        ctx.imageSmoothingEnabled = true;
        ctx.drawImage(this._source, 0, 0, width, height);

        this._source = canvas;
    }
Example #10
0
		run: function(connection, collections, data){
            if(data.room == undefined) return {error: "Need to specify roomID!"};
            var roomID = data.room;
            var room = collections.rooms.findWhere({uid: roomID});
            if(room == undefined) return {error: "Need to specify valid roomID!"};

            var newID = collections.drawers.nextID();

			var newDrawer = new Drawer({
					id: newID,
                    room: room.get("uid"),
					color: getRandomColor()
			});
			connection.room = room;
			connection.drawer = newDrawer;
            collections.drawers.add(newDrawer);
			connection.recheckAllPermissions();

            var canvas = this.roomToCanvas[roomID];
			if (canvas != undefined && data.width != undefined && data.height != undefined){
				var tempCanvas = new Canvas(data.width,data.height),
				tmpCtx = tempCanvas.getContext("2d");
				tmpCtx.drawImage(canvas, 0, 0),
                ctx = canvas.getContext("2d");

                newDrawer.on("change", function(drawer){
                    var x = drawer.get('x');
                    var y = drawer.get('y');
                    var prevX = drawer.get('prevX');
                    var prevY = drawer.get('prevY');
                    var clicked = drawer.get('clicked');
                    var moving = drawer.get('moving');
                    var strokeSize = drawer.get('strokeSize');
                    if (clicked && !moving){
                        ctx.beginPath();
                        ctx.arc(x, y, strokeSize/2, 0, 2*Math.PI);
                        ctx.fillStyle = drawer.get('color');
                        ctx.fill();
                    }else if(clicked && moving){
                        ctx.beginPath();
                        ctx.strokeStyle = drawer.get('color');
                        ctx.lineWidth = strokeSize;
                        ctx.lineCap = "round";
                        ctx.lineJoin = "round";

                        ctx.moveTo(prevX,prevY);
                        ctx.lineTo(x,y);
                        ctx.stroke();
                    }
                });

				return {success: "Logged in!", id: newID, dataURL: tempCanvas.toDataURL(), room: roomID};
			}

			return {success: "Logged in!", id: newID, room: roomID};
		}
Example #11
0
app.get('/', function(request, response) {
  try {
    var queryObject = url.parse(request.url,true).query;
    console.log(queryObject);

    var text = queryObject.text || 'no text';

    var Image = Canvas.Image;
    var canvas = new Canvas(400, 200);
    var ctx = canvas.getContext('2d');
    ctx.fillStyle = "#FFFFFF";
    ctx.fillRect(0,0,400,200);

    ctx.fillStyle = "#000000";
    ctx.font = '14px fontOpenSans';

    function wrapText(context, text, x, y, maxWidth, lineHeight) {
        var words = text.split(' ');
        var line = '';

        for(var n = 0; n < words.length; n++) {
          var testLine = line + words[n] + ' ';
          var metrics = context.measureText(testLine);
          var testWidth = metrics.width;
          if (testWidth > maxWidth && n > 0) {
            context.fillText(line, x, y);
            line = words[n] + ' ';
            y += lineHeight;
          }
          else {
            line = testLine;
          }
        }
        context.fillText(line, x, y);
    }
      
    wrapText(ctx, text, (400-360)/2, 60, 360, 20);
    

    if (queryObject.base64) {
      canvas.toDataURL('image/png', function(err, png){ 
        if (!err) {
          response.end(png);
        } else {
          response.end('problem generating png: ' + err.toString());
        }
      });
    } else {
      var stream = canvas.createPNGStream();
      response.writeHead(200, {"Content-Type": "image/png"});
      stream.pipe(response);
    }
  } catch(e) {
    response.end('something went wrong: ' + e.message || e.toString());
  }
});
Example #12
0
 function createCanvas () {
   var canvas = new Canvas(ctxWidth, ctxHeight);
   var ctx = canvas.getContext('2d');
   lodash.each(sprites, function (sprite) {
     sprite.total_width = ctxWidth;
     sprite.total_height = ctxHeight;
     ctx.drawImage(sprite.img, sprite.x, sprite.y, sprite.width, sprite.height);
   });
   return canvas;
 }
  it('should set background', function () {
    var canvas = new Canvas();
    var ctx = canvas.getContext("2d");
    JsBarcode(canvas, "Hello", {format: "CODE128", background: "#f00"});

    var topLeft = ctx.getImageData(0,0,1,1);
    assert.equal(255, topLeft.data[0]);
    assert.equal(0, topLeft.data[1]);
    assert.equal(0, topLeft.data[2]);
  });
 /**
  * @param {number} height
  * @return {Context2d}
  */
 static createCanvasContext(height) {
     let canvas = new Canvas(GIF_WIDTH, height);
     let context = canvas.getContext('2d');
     if(SOURCE_SANS_PRO !== null) {
         context.addFont(SOURCE_SANS_PRO);
     }
     let fontName = SOURCE_SANS_PRO !== null ? 'aSourceSansPro' : '"Lucida Sans Unicode"';
     context.font = `13px ${fontName}`;
     return context;
 }
Example #15
0
  return BPromise.try(() => {
    const canvas = new Canvas(width, height);
    const ctx = canvas.getContext('2d');

    BPromise.promisify(canvas.toBuffer);
    const chart = new Chart(ctx).Line(chartData, chartOptions);
    chart.draw();

    return canvas.toBuffer();
  });
Example #16
0
								lwi.toBuffer("png",function(e,b){
									var img = new Canvas.Image;
									img.src = b;
									var cnv = new Canvas(img.width, img.height);
									var ctx = cnv.getContext('2d');
									ctx.drawImage(img,0,0);
									
									dfd.resolve(ctx);
								
								});
Example #17
0
exports.resizeCanvas = function(canvas, width, height) {
  var resizeCanvas = new Canvas(width, height);
  var ctx = resizeCanvas.getContext('2d');
  ctx.patternQuality = "best";

  ctx.drawImage(canvas, 0, 0, canvas.width, canvas.height,
                0, 0, width, height);

  return resizeCanvas;
}
Example #18
0
 'test Context2d#patternQuality': function(assert){
   var canvas = new Canvas(200, 200)
     , ctx = canvas.getContext('2d');
   
   assert.equal('good', ctx.patternQuality);
   ctx.patternQuality = 'best';
   assert.equal('best', ctx.patternQuality);
   ctx.patternQuality = 'invalid';
   assert.equal('best', ctx.patternQuality);
 },
Example #19
0
    fs.readFile(srcPath, function (err, data) {
        if (err) {
            console.error(err);
            return err;
        }

        var psd = new Parser(data);
        psd.parse();

        var height = psd.header.rows;
        var width = psd.header.columns;

        var pixels = new PixelArray(width, height);

        var color = psd.imageData.createColor(psd.header, psd.colorModeData);

        var x, y, index;
        for(y = 0; y < height; ++y) {
            for(x = 0; x < width; ++x) {
                index = (y * width + x);
                pixels[index * 4    ] = color[0][index];
                pixels[index * 4 + 1] = color[1][index];
                pixels[index * 4 + 2] = color[2][index];
                pixels[index * 4 + 3] = 255;
            }
        }

        var canvas = new Canvas(width, height);
        var ctx = canvas.getContext('2d');

        var imageData = new ImageData(pixels);
        ctx.putImageData(imageData, 0, 0);

        var dir = __dirname + '/../public/uploads/' + id;
        fs.mkdir(dir, function () {
            canvas
                .pngStream()
                .pipe(fs.createWriteStream(dir + '/full.png'))
                .on('finish', function() {
                    console.log(dir);

                    gm(dir + '/full.png')
                        .resize(300, 200)
                        .write(dir + '/thumb.png', function (err) {
                            if (err) {
                                console.error(err);
                                res.send(err);
                            } else {
                                console.log('hallo');
                                eval(cb);
                            }
                        });
                });
        });
    });
const generateTile = (tileConfig) => {
  const pixels = generateHeightMap(tileConfig)
  const {size} = tileConfig
  
  const canvas = new Canvas(size.x, size.y)
  const ctx = canvas.getContext('2d')
    
  ctx.putImageData(new ImageData(pixels, size.x, size.y) , 0, 0)
  
  return canvas.pngStream()
}
Example #21
0
  var renderOverlay = function(z, x, y, bearing, pitch, w, h, scale,
                               path, query) {
    if (!path || path.length < 2) {
      return null;
    }
    var precisePx = function(ll, zoom) {
      var px = mercator.px(ll, 20);
      var scale = Math.pow(2, zoom - 20);
      return [px[0] * scale, px[1] * scale];
    };

    var center = precisePx([x, y], z);

    var mapHeight = 512 * (1 << z);
    var maxEdge = center[1] + h / 2;
    var minEdge = center[1] - h / 2;
    if (maxEdge > mapHeight) {
      center[1] -= (maxEdge - mapHeight);
    } else if (minEdge < 0) {
      center[1] -= minEdge;
    }

    var canvas = new Canvas(scale * w, scale * h);
    var ctx = canvas.getContext('2d');
    ctx.scale(scale, scale);
    if (bearing) {
      ctx.translate(w / 2, h / 2);
      ctx.rotate(-bearing / 180 * Math.PI);
      ctx.translate(-center[0], -center[1]);
    } else {
      // optimized path
      ctx.translate(-center[0] + w / 2, -center[1] + h / 2);
    }
    var lineWidth = query.width !== undefined ?
                    parseFloat(query.width) : 1;
    ctx.lineWidth = lineWidth;
    ctx.strokeStyle = query.stroke || 'rgba(0,64,255,0.7)';
    ctx.fillStyle = query.fill || 'rgba(255,255,255,0.4)';
    ctx.beginPath();
    path.forEach(function(pair) {
      var px = precisePx(pair, z);
      ctx.lineTo(px[0], px[1]);
    });
    if (path[0][0] == path[path.length - 1][0] &&
        path[0][1] == path[path.length - 1][1]) {
      ctx.closePath();
    }
    ctx.fill();
    if (lineWidth > 0) {
      ctx.stroke();
    }

    return canvas.toBuffer();
  };
Example #22
0
var cropToCenter = stitch.cropToCenter = function(canvas, width, height) {
  var target = new Canvas(width, height),
      targetCtx = target.getContext("2d");

  var xOffset = (canvas.width - width) / 2,
      yOffset = (canvas.height - height) / 2;

  targetCtx.drawImage(canvas, -xOffset, -yOffset);

  return target;
};
 callback: function(err, result) {
   var expectedImage = new Canvas.Image();
   expectedImage.src = fs.readFileSync(base + '.png');
   var expectedCanvas = new Canvas(expectedImage.width, expectedImage.height);
   var ctx = expectedCanvas.getContext('2d');
   ctx.drawImage(expectedImage, 0, 0, expectedImage.width, expectedImage.height);
 
   // real test
   expect(imagediff.equal(result, expectedCanvas, 20)).to.be.true;
   done();
 }
Example #24
0
module.exports = function () {
  var W = 90;
  var H = 30;
  var canvas = new Canvas(W, H);
  var ctx = canvas.getContext('2d');
  var items = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPRSTUVWXYZ23456789'.split('');
  var vcode = '';

  ctx.fillStyle = '#f3fbfe';
  ctx.fillRect(0, 0, 90, 30);
  ctx.globalAlpha = .8;
  ctx.font = '15px sans-serif';

  for (var i = 0; i < 10; i++) {
    ctx.fillStyle = 'rgb(' + randInt(150, 225) + ',' + randInt(150, 225) + ',' + randInt(150, 225) + ')';
    for (var j = 0; j < 5; j++) {
      ctx.fillText(items[randInt(0, items.length)], randFloat(-10, W + 10), randFloat(-10, H + 10));
    }
  }

  var color = 'rgb(' + randInt(1, 120) + ',' + randInt(1, 120) + ',' + randInt(1, 120) + ')';
  ctx.font = 'bold 24px sans-serif';

  for (var i = 0; i < 4; i++) {
    var j = randInt(0, items.length);
    ctx.fillStyle = color;
    ctx.fillText(items[j], 5 + i * 23, 30);
    ctx.fillText(items[j], 0, 0);
    vcode += items[j];
  }

  ctx.beginPath();
  ctx.strokeStyle = color;
  var A = randFloat(10, H / 2);
  var b = randFloat(H / 4, 3 * H / 4);
  var f = randFloat(H / 4, 3 * H / 4);
  var T = randFloat(H * 1.5, W);
  var w = 2 * Math.PI / T;
  var S = function(x) {
    return A * Math.sin(w * x + f) + b;
  };
  ctx.lineWidth = 3;
  for (var x = -20; x < 200; x += 4) {
    ctx.moveTo(x, S(x));
    ctx.lineTo(x + 3, S(x + 3));
  }
  ctx.closePath();
  ctx.stroke();

  return {
    code: vcode.toLowerCase(),
    dataURL: canvas.toDataURL()
  };
};
Example #25
0
    img.onload = function() {
	var canvas = new Canvas(img.width, img.height)
	, ctx = canvas.getContext('2d');
	
	ctx.drawImage(img, 0, 0, img.width, img.height);
	var imageData = ctx.getImageData(0,0,canvas.width,canvas.height);
	for (var i=0; i < imageData.data.length; i+=4) {    
	    //adjust curves
	    if (options.desaturate !== false) {	    
		var average = ( r[imageData.data[i]] + g[imageData.data[i+1]] + b[imageData.data[i+2]] ) / 3;            
		imageData.data[i  ] += Math.round( ( average - imageData.data[i  ] ) * options.desaturate );
		imageData.data[i+1] += Math.round( ( average - imageData.data[i+1] ) * options.desaturate );
		imageData.data[i+2] += Math.round( ( average - imageData.data[i+2] ) * options.desaturate );	    
	    } else {
		imageData.data[i  ] = r[imageData.data[i  ]];
		imageData.data[i+1] = g[imageData.data[i+1]];
		imageData.data[i+2] = b[imageData.data[i+2]];
	    }	
	    // screen layer mode with solid color rbg(227,12,169) and 10% opacity
	    if (options.screen !== false) {
		imageData.data[i  ] = 255 - ((255 - imageData.data[i  ]) * (255 - options.screen.red * options.screen.strength) / 255);
		imageData.data[i+1] = 255 - ((255 - imageData.data[i+1]) * (255 - options.screen.green * options.screen.strength) / 255);
		imageData.data[i+2] = 255 - ((255 - imageData.data[i+2]) * (255 - options.screen.blue * options.screen.strength) / 255);
	    }	
	    //add noise
	    if (options.noise > 0) {
		var noise = Math.round(options.noise - Math.random() * options.noise/2);
		
		var dblHlp = 0;
		for(var k=0; k<3; k++){
		    dblHlp = noise + imageData.data[i+k];
		    imageData.data[i+k] = ((dblHlp > 255)? 255 : ((dblHlp < 0)? 0 : dblHlp));
		}
	    }		
	};
	ctx.putImageData(imageData, 0, 0);
	var out = fs.createWriteStream(to)
	, stream = canvas.createJPEGStream();
	
	stream.on('data', function(chunk){
	    out.write(chunk);
	});

	stream.on('end', function(){
	    out.end();
	    console.log("end");
	});

	out.on('close', function(){
	    console.log("close");
	    callback();
	});

    };
Example #26
0
//压缩图片
function _crop(jsonReq,callback){
    var buf=jsonReq.buf;
    var size=parseInt(jsonReq.size)||100;
    var img=new Image;
        img.src=buf;
    var w=img.width, 
        h=img.height;
    var smallH,smallW;
        if(jsonReq.imageType=="fill"){
            var canvas=new Canvas(size,size);
            var ctx=canvas.getContext("2d");
            if(w>h){
                smallH=size;
                smallW=(size/h)*w;
                ctx.drawImage(img,-(smallW-size)/2,0,smallW,smallH);
            }else{
                smallW=size;
                smallH=(size/w)*h;
                ctx.drawImage(img,0,-(smallH-size)/2,smallW,smallH);
            }
        }else{
            if(w>h){
                smallW=size;
                smallH=(size/w)*h;
            }else{
                smallH=size;
                smallW=(size/h)*w;
            }
            var canvas=new Canvas(smallW,smallH);
            var ctx=canvas.getContext("2d");
            ctx.drawImage(img,0,0,smallW,smallH);
        }
        //canvas.toBuffer(callback);
        /*
        ctx.fillStyle = "#fff";
        ctx.font ='bold 20px Arial';
        ctx.fillText("PICONLINE",canvas.width-100,canvas.height-50);
        */

        save1(canvas,callback);
}
Example #27
0
 decodeImage.onload = function() {
     var w = decodeImage.width,
         h = decodeImage.height;
     decodeCanvas = new Canvas(w, h);
     decodeCanvas.getContext('2d').drawImage(
         decodeImage, 0, 0, w, h);
     decodeCanvas.toBuffer(function(err, buf){
         fs.writeFileSync(test_case.decode_path, buf);
         assert(fs.existsSync(test_case.decode_path) === true);
         done();
     });
 };
Example #28
0
 qrImage.onload = function() {
     var w = qrImage.width,
         h = qrImage.height;
     qrCanvas = new Canvas(w, h);
     qrCanvas.getContext('2d').drawImage(
         qrImage, 0, 0, w, h);
     var out = fs.createWriteStream(test_case.qr_path);
     var stream = qrCanvas.pngStream();
     stream.pipe(out);
     assert(fs.existsSync(test_case.qr_path) === true);
     done();
 };
Example #29
0
function dataToCanvas(imagedata) {
  img = new Canvas.Image();
  img.src = new Buffer(imagedata, 'binary');

  var canvas = new Canvas(img.width, img.height);
  var ctx = canvas.getContext('2d');
  ctx.patternQuality = "best";

  ctx.drawImage(img, 0, 0, img.width, img.height,
    0, 0, img.width, img.height);
  return canvas;
}
Example #30
0
 decorate: function(image) {
   var w = image.width;
   var h = image.height;
   var canvas = new Canvas(w, h);
   var ctx = canvas.getContext('2d');
   drawImage(ctx, conf.mask, w, h);
   ctx.globalCompositeOperation = 'source-in';
   drawImage(ctx, image.src, w, h);
   ctx.globalCompositeOperation = 'source-over';
   drawImage(ctx, conf.frame, w, h);
   return canvas.toBuffer();
 },