create image on nodejs with graphicsmagick

Lupus picture Lupus · Mar 9, 2012 · Viewed 15.7k times · Source

I need a way to create an image on graphicsMagick via node.js

Normally I can manage this with;

gm convert -background transparent -pointsize 30 -gravity Center label:türkçee HEEEEEY.png

I need the equivalent of this input in node.js like;

var gm = require('gm');
gm.background('transparent')
  .gravity('Center')
  .fontSize(30)
  .drawText('Test')
  .write('HEEEY.png')

PS: I don't want to give image size as parameter. (sorry for my english)

Answer

Linus Thiel picture Linus Thiel · Mar 9, 2012

Look in the node-grapicksmagick README, under "creating an image".

// creating an image
gm(200, 400, "#ddff99f3")
.drawText(10, 50, "from scratch")
.write("/path/to/brandNewImg.jpg", function (err) {
  // ...
});