Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Node-canvas

 Node-canvas

Node-canvas
Sendagaya.js@pixiv
2014-03-19

5分で終わらなかった

Harukasan

March 19, 2014
Tweet

More Decks by Harukasan

Other Decks in Technology

Transcript

  1. Harukasan a.k.a MICHII Shunsuke ಓҪढ़հ 2012 pixiv Inc. ΠϯϑϥνʔϜ Nginx

    / Apache / MySQL / MongoDB Kyototycoon / Solr / Traffic Server / Fluentd Kibana / Capistrano / Ruby on Rails / Macbook
  2. Ý

  3. Ý

  4. Ý

  5. Create canvas and draw Canvas = require('canvas') canvas = new

    Canvas(320, 240) ctx = canvas.getContext('2d') ! ctx.save() ctx.fillStyle = '#ff0000' ctx.fillRect(100, 100, 200, 200) ctx.restore()
  6. Load Image {Image} = Canvas = require 'canvas' fs =

    require 'fs' path = 'test.png' fs.readFile path, (err, data) -> return next(null) if err or not data img = new Image img.src = data ctx.drawImage img, 0, 0, img.width, img.height
  7. Output to PNG with Stream path = ‘test.png' out =

    fs.createWriteStream path out.on 'finish', -> console.log 'fs: finish' ! canvas.createPNGStream().pipe out
  8. Output to JPEG with Stream path = 'test.png' out =

    fs.createWriteStream path out.on 'finish', -> console.log 'fs: finish' ! canvas.createJPEGStream(quality: 75).pipe out
  9. Render Image Quality ctx.patternQuality = fast # => nearest good

    # => biliiner best # => biliinear nearest bilinear