gm
gm copied to clipboard
How to enable word wrap with graphicsmagick??
i m creating images with gn and its awesome so far but now m stuck that text is overflowing from image and can anyone help me how to fix it ?
here is the image:

and my code is:
gm(1200, 630, req.query.color)
.fontSize(50)
.fill("#fff")
.pointSize(50)
.stroke("#000")
.strokeWidth(2)
.font( __dirname + '/font/impact.ttf')
.drawText(10, 50, req.query.url,"Center")
.write(__dirname + "/imgs/brandNewImg.jpg", function (err) {
if (!err) {
res.sendFile(__dirname + "/imgs/brandNewImg.jpg", {}, function (err) {
if (!err) {
fs.unlinkSync(__dirname + "/imgs/brandNewImg.jpg");
} else {
console.log(err);
res.status(err.status).end("Error occured while creating images");
}
});
} else {
console.log(err);
res.send("Some Error occured");
}
});
please help and thanks in advance! :)
This is not the perfect solution, but what I did in my case was:
const title = job.title.substring(0, 25)
gm(image)
.drawText(50, 170, title.length === job.title.length ? title : `${title}...`)
Hi!
You can use ImageMagick's caption and the .out(...) function which is poorly documented in my opinion.
Example: .out('-size', '400x', 'caption: "text to be wrapped"') => the text to be wrapped will be of 400px maximum width.
You might eventually use .out('-composite') in order to merge the caption in another image.