How to draw rectangle by node.js and graphicsmagick JavaScript 04.02.2016

Simple note about how to draw rectangle by node.js and graphicsmagick and save as PNG file.

Install graphicsmagick

# archlinux
sudo pacman -S graphicsmagick

# ubuntu 
sudo add-apt-repository ppa:dhor/myway
sudo apt-get update
sudo apt-get install graphicsmagick

Install gm(GraphicsMagick for node.js)

npm install gm

Create canvas and draw two rectangle, save as PNG file.

var gm = require('gm')

// image size ang bg color
var pic = gm(500, 500, "white")

// rectangle 1
pic.fill('white')
pic.stroke("#6C68FF", 1)
pic.drawRectangle(30, 40, 200, 400)

// rectangle 2
pic.fill('white')
pic.stroke("#FF6C68", 1)
pic.drawRectangle(240, 40, 400, 400)

// save
pic.write('t.png', function (err) {
    if ( err ) throw err;
});

Also you can read how to draw rectangle in Python.