Search code examples
node.jsgraphicsmagick

How do I change the color of text I'm drawing with node graphicsmagick?


I'm trying to output white text on a red background but the text is outputting as black. As far as I can tell, there's no fontColor or (thinking with my CSS hat) color method I can call on it.

I was under the impression that fill would handle this but that doesn't seem to be the case.

Here's my code:

gm(600, 170, "#F15623")
    .drawText(0, 0, 'from scratch', 'Center')
    .fill('#FFFFFF')
    .font( __dirname + '/../fonts/GothamCond-Medium.otf')
    .fontSize( '100px' )
    .write( filename, function (err) {
        if (err) {
            throw err;
        } else {
            callback( null );
        }
    });

Solution

  • I needed to specify the fill method BEFORE the text so it would be filled with that color.

    gm(600, 170, "#F15623")
        .fill('#FFFFFF')
        .drawText(0, 0, 'from scratch', 'Center')
        .font( __dirname + '/../fonts/GothamCond-Medium.otf')
        .fontSize( '100px' )
        .write( filename, function (err) {
            if (err) {
                throw err;
            } else {
                callback( null );
            }
        });