Monday 10 April 2017

Graphicsmagick: How to draw text to fit a specific box (width/height)

I'm using GraphicsMagick's node js module (http://aheckmann.github.io/gm/docs.html#drawing-primitives).

In my Node JS application I need to add a text label to an existing image, such that: 1) If the text is longer than the image size, the text auto-wraps around to the next line 2) If the text is not able to fit into the image, the font size of the text is automatically adjusted (reduced) to fit into the box of the image

The available APIs from GraphicsMagick's Node JS module are:

gm("img.png").drawText(x, y, text [, gravity])

But this does not provide any options to fit the text into the box per the two requirements above. If I use this API alone I will need to manually break the text, and change the text font size to fit the image, but even for that I will need to first be able to measure the text size. Is there a way to do that?

Any suggestions?



via Gaurav Jain

No comments:

Post a Comment