You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

45 lines
898 B

9 years ago
var fs = require('fs')
var path = require('path')
var Canvas = require('..')
9 years ago
var canvas = new Canvas(200, 200)
var ctx = canvas.getContext('2d')
9 years ago
ctx.globalAlpha = 0.2
9 years ago
ctx.strokeRect(0, 0, 200, 200)
ctx.lineTo(0, 100)
ctx.lineTo(200, 100)
ctx.stroke()
9 years ago
ctx.beginPath()
ctx.lineTo(100, 0)
ctx.lineTo(100, 200)
ctx.stroke()
9 years ago
ctx.globalAlpha = 1
ctx.font = 'normal 40px Impact, serif'
9 years ago
ctx.rotate(0.5)
ctx.translate(20, -40)
9 years ago
ctx.lineWidth = 1
ctx.strokeStyle = '#ddd'
ctx.strokeText('Wahoo', 50, 100)
9 years ago
ctx.fillStyle = '#000'
ctx.fillText('Wahoo', 49, 99)
9 years ago
var m = ctx.measureText('Wahoo')
9 years ago
ctx.strokeStyle = '#f00'
9 years ago
ctx.strokeRect(
49 + m.actualBoundingBoxLeft,
99 - m.actualBoundingBoxAscent,
m.actualBoundingBoxRight - m.actualBoundingBoxLeft,
9 years ago
m.actualBoundingBoxAscent + m.actualBoundingBoxDescent
)
9 years ago
canvas.createPNGStream().pipe(fs.createWriteStream(path.join(__dirname, 'text.png')))