Created
August 25, 2016 19:59
-
-
Save markni/5b10f9319b0a5ccf42bdfff569979a7e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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