Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

🎨 GD graphics library (libgd) C++ bindings for Node.js.

License

NotificationsYou must be signed in to change notification settings

y-a-v-a/node-gd

Repository files navigation

node-gd logo

node-gd

GD graphics library,libgd, C++ bindings for Node.js. This version is the community-maintainedofficial NodeJS node-gd repo. Withnode-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.

Installation

Quick Installation (Recommended)

For most users, installation is now much simpler thanks to prebuilt binaries:

$ npm install node-gd

This will automatically download and install a precompiled binary for your platform (macOS x64/arm64, Linux x64/arm64) and Node.js version. No build tools or system dependencies required!

Manual Installation

If prebuilt binaries are not available for your platform or you want to build from source:

Preconditions

Have environment-specific build tools available. Next to that: to take full advantage of node-gd, best is to ensure you install the latest version of libgd2, which can be found at thelibgd github repository.

On Debian/Ubuntu

$ sudo apt-get install libgd-dev# libgd$ npm install node-gd

On RHEL/CentOS

$ sudo yum install gd-devel$ npm install node-gd

On Mac OS/X

Using Homebrew

$ brew install pkg-config gd$ npm install node-gd

...or using MacPorts

$ sudo port install pkgconfig gd2$ npm install node-gd

Platform Support

  • ✅ macOS - x64 and arm64 (Apple Silicon) - prebuilt binaries available
  • ✅ Linux - x64 and arm64 - prebuilt binaries available
  • ✅ FreeBSD - manual build only
  • ❌ Windows - Not supported

Build from Source

If you need to build from source or want to customize the build:

$ git clone https://github.com/y-a-v-a/node-gd.git$cd node-gd$ npm install# This will fallback to building from source if no prebuilt binary

Supported Node.js Versions

Prebuilt binaries are available for Node.js versions 16, 18, 20, and 22. The package supports Node.js 14+ but prebuilt binaries are only provided for actively maintained versions.

Usage

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 whilegd.createTrueColor() will create a true color image.

API

Full API documentation and more examples can be found in thedocs directory or atthe dedicated github page.

Examples

Example of creating a rectangular image with a bright green background and in magenta the text "Hello world!"

// Import libraryimportgdfrom'node-gd';// Create blank new image in memoryconstimg=awaitgd.create(200,80);// Set background colorimg.colorAllocate(0,255,0);// Set text colorconsttxtColor=img.colorAllocate(255,0,255);// Set full path to font fileconstfontPath='/full/path/to/font.ttf';// Render string in imageimg.stringFT(txtColor,fontPath,24,0,10,60,'Hello world!');// Write image buffer to diskawaitimg.savePng('output.png',1);// Destroy image to clean memoryimg.destroy();

Example of drawing a red lined hexagon on a black background:

importgdfrom'node-gd';constimg=awaitgd.createTrueColor(200,200);constpoints=[{x:100,y:20},{x:170,y:60},{x:170,y:140},{x:100,y:180},{x:30,y:140},{x:30,y:60},{x:100,y:20},];img.setThickness(4);img.polygon(points,0xff0000);awaitimg.saveBmp('test1.bmp',0);img.destroy();

Another example:

importgdfrom'node-gd';constimg=awaitgd.openFile('/path/to/file.jpg');img.emboss();img.brightness(75);awaitimg.file('/path/to/newFile.bmp');img.destroy();

Some output functions are synchronous because they are handled by libgd. An example of this is the creation of animated GIFs.

License & copyright

SinceDecember 27th 2012, node-gd is licensed under an MIT license.

The MIT License (MIT)Copyright (c) 2010-2020 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.

Contributors

The current version is based on code created by taggon,here the original author's repo, and on the additions bymikesmullin. Porting node-gd tonode-addon-api and extending the API is done byy-a-v-a, on Twitter as@_y_a_v_a_. See theCONTRIBUTORS.mdfile for a list of all contributors.

About

🎨 GD graphics library (libgd) C++ bindings for Node.js.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors18


[8]ページ先頭

©2009-2025 Movatter.jp