GD graphics library, libgd, C++ bindings for Node.js. This version is the community-maintained official NodeJS node-gd repo. With
node-gd you can easily create, manipulate, open and save paletted and true color images from and to a variety of image formats including JPEG, PNG, GIF and BMP.
Have environment-specific build tools available.
$ sudo apt-get install libgd2-dev # libgd$ npm install node-gd
$ sudo yum install gd-devel$ npm install node-gd
$ brew install pkg-config gd$ npm install node-gd
...or using MacPorts
$ sudo port install pkgconfig gd2$ npm install node-gd
Sorry, will not build on Windows.
There are different flavours of images, of which the main ones are palette-based (up to 256 colors) and true color images (millions of colors). GIFs are always palette-based, PNGs can be both palette-based or true color. JPEGs are always true color images.
gd.create() will create a palette-based base image while
gd.createTrueColor() will create a true color image.
Full API documentation and more examples can be found in the docs directory.
gd.createTrueColor are async. You will have to modify your code. This means that you should either change all
gd.create calls to
gd.createTrueColorSync or rewrite those call and wrap further calls in a callback.
Example of synchronously creating a rectangular image with a bright green background and in magenta the text "Hello world!"
// Require libraryvar gd = ;// Create blank new image in memoryvar img = gd;// Set background colorimg;// Set text colorvar txtColor = img;// Set full path to font filevar fontPath = '/full/path/to/font.ttf';// Render string in imageimg;// Write image buffer to diskimg;// Destroy image to clean memoryimg;
Asynchronous example of drawing a red lined hexagon on a black background:
var gd = ;gd;
var gd = ;gd;
Some output functions are synchronous because they are handled by libgd. An example of this is the creation of animated GIFs.
Since December 27th 2012, node-gd is licensed under an MIT license.
The MIT License (MIT) Copyright (c) 2010-2016 the contributors.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
The current version is based on code created by taggon, here the original author's repo, and on the additions by mikesmullin. Porting node-gd to nan and extending the API is done by y-a-v-a, on Twitter as @_y_a_v_a_.