Skip to content

Instantly share code, notes, and snippets.

@markni
Created August 25, 2016 19:59
Show Gist options
  • Save markni/5b10f9319b0a5ccf42bdfff569979a7e to your computer and use it in GitHub Desktop.
Save markni/5b10f9319b0a5ccf42bdfff569979a7e to your computer and use it in GitHub Desktop.
var path = require('path');
var Jimp = require("jimp");
var gd = require('node-gd');
var gm = require('gm').subClass({imageMagick: true});
const width = 800;
const height = 100;
const fontSize = 64;
const text = 'LABEL 1232-235-123 GD';
//----------gm-----------
gm(width, height, "#ffffff")
.font(fontPath)
.fontSize(fontSize)
.fill('#000000')
.drawText(0, fontSize, text)
.write("gm.png", function (err) {
});
//--------jimp-------------
var image = new Jimp(width, height, 0xFFFFFFFF, function (err, image) {
var self = this;
Jimp.loadFont(Jimp.FONT_SANS_64_BLACK).then(function (font) {
self.print(font, 0, 0, text).write("jimp.png");
});
});
//----------gd-----------
var img = gd.createSync(width, height);
img.colorAllocate(255, 255, 255);
var txtColor = img.colorAllocate(0, 0, 0);
var fontPath = path.resolve(__dirname, 'OpenSans-Regular.ttf');
img.stringFT(txtColor, fontPath, fontSize * 0.75 , 0, 0, fontSize, text); //point not pixel
img.savePng('gd.png', 1, function(err) {
if(err) {
throw err;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment