GithubHelp home page GithubHelp logo

sonaldo / node-gd Goto Github PK

View Code? Open in Web Editor NEW

This project forked from y-a-v-a/node-gd

0.0 0.0 0.0 5.1 MB

๐ŸŽจ GD graphics library (libgd) C++ bindings for Node.js.

License: MIT License

Shell 0.16% JavaScript 27.90% C++ 70.04% Python 1.74% Dockerfile 0.16%

node-gd's Introduction

node-gd logo

node-gd

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.

Installation

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 the libgd 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

Will not build on Windows!

Sorry, will not build on Windows. I have no Windows machine to make it work. It could work, but I just don't have the stuff at hand.

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

API

Full API documentation and more examples can be found in the docs directory or at the dedicated github page.

Examples

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

// Import library
import gd from 'node-gd';

// Create blank new image in memory
const img = await gd.create(200, 80);

// Set background color
img.colorAllocate(0, 255, 0);

// Set text color
const txtColor = img.colorAllocate(255, 0, 255);

// Set full path to font file
const fontPath = '/full/path/to/font.ttf';

// Render string in image
img.stringFT(txtColor, fontPath, 24, 0, 10, 60, 'Hello world!');

// Write image buffer to disk
await img.savePng('output.png', 1);

// Destroy image to clean memory
img.destroy();

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

import gd from 'node-gd';

const img = await gd.createTrueColor(200, 200);

const points = [
  { 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);
await img.saveBmp('test1.bmp', 0);
img.destroy();

Another example:

import gd from 'node-gd';

const img = await gd.openFile('/path/to/file.jpg');

img.emboss();
img.brightness(75);
await img.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

Since December 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 by mikesmullin. Porting node-gd to node-addon-api and extending the API is done by y-a-v-a, on Twitter as @_y_a_v_a_. See the CONTRIBUTORS.md file for a list of all contributors.

node-gd's People

Contributors

y-a-v-a avatar mikesmullin avatar sonaldo avatar sheershoff avatar andris9 avatar topaxi avatar zaro avatar vladislav805 avatar buraktamturk avatar danyshaanan avatar blakmatrix avatar gabrieledarrigo avatar holixus avatar tdebarochez avatar tim-smart avatar dependabot[bot] avatar kmpm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.