2012-03-12 51 views
2

我想申請一個透明的圓形掩碼來將png圖片發送到我的node.js服務器;以便我可以在較舊的瀏覽器和電子郵件客戶端中顯示圓形圖片。添加並保存一個圓形掩碼框圖像

我已經在使用node-canvas來調整和裁剪我的圖片,所以我想知道這種圖片處理是否可以通過canvas API完成。

+0

你能更詳細地描述操作嗎? – 2012-03-12 15:42:45

回答

1

我設法寫什麼,我想這是代碼

{}圖片帆布= =需要 '畫布' FS =需要 'FS'

IMG =新的圖像 img.onload = - >

canvas = new Canvas 200, 200 
cxt = canvas.getContext '2d' 
cxt.drawImage img, sx, sy, sw, sh, dx, dy, dw, dh 
cxt.globalCompositeOperation = "destination-atop" 

cxt.beginPath() 
cxt.arc 100, 100, 50, 0, Math.PI*2, true 
cxt.fill() 
cxt.closePath() 

canvas.toBuffer (err, buf) -> 
    return cb(err) if err 
    fs.writeFile "/tmp/dest.jpeg", buf, -> console.log 'test done !' 

img.src = '/tmp/src.jpeg'