Module basic module

Module gd

Image file processing module

Basic module. Can be used to create and manipulate image files, reference method:

1
var gd = require('gd');

Static function

create

Create a new image

1 2 3
static Image gd.create(Integer width, Integer height, Integer color = gd.TRUECOLOR) async;

Call parameters:

  • width: Integer, specify the image width
  • height: Integer, specify the image height
  • color: Integer, specify the image type, the allowed value is gd.TRUECOLOR or gd.PALETTE

Return result:

  • Image, Return the successfully created image object

load

Decode image from format data

1
static Image gd.load(Buffer data) async;

Call parameters:

  • data: Buffer, Given decoded image data

Return result:

  • Image, Return the successfully decoded image object

Decode the image from the stream object

1
static Image gd.load(SeekableStream stm) async;

Call parameters:

  • stm: SeekableStream, The stream object where the given image data is located

Return result:

  • Image, Return the successfully decoded image object

Decode image from specified file

1
static Image gd.load(String fname) async;

Call parameters:

  • fname: String, specify the file name

Return result:

  • Image, Return the successfully decoded image object

rgb

Generate combined colors from rgb color components

1 2 3
static Integer gd.rgb(Integer red, Integer green, Integer blue);

Call parameters:

  • red: Integer, the red component, the range is 0-255
  • green: Integer, the green component, the range is 0-255
  • blue: Integer, blue component, range 0-255

Return result:

  • Integer, Returns the combined color

rgba

Generate combined colors from rgba color components

1 2 3 4
static Integer gd.rgba(Integer red, Integer green, Integer blue, Number alpha);

Call parameters:

  • red: Integer, the red component, the range is 0-255
  • green: Integer, the green component, the range is 0-255
  • blue: Integer, blue component, range 0-255
  • alpha: Number, the transparent component, the range is 0.0-1.0

Return result:

  • Integer, Returns the combined color

hsl

Generate combined colors from hsl color components

1 2 3
static Integer gd.hsl(Number hue, Number saturation, Number lightness);

Call parameters:

  • hue: Number, hue component, the range is 0-360
  • saturation: Number, saturation component, the range is 0.0-1.0
  • lightness: Number, the brightness component, the range is 0.0-1.0

Return result:

  • Integer, Returns the combined color

hsla

Generate combined colors from hsla color components

1 2 3 4
static Integer gd.hsla(Number hue, Number saturation, Number lightness, Number alpha);

Call parameters:

  • hue: Number, hue component, the range is 0-360
  • saturation: Number, saturation component, the range is 0.0-1.0
  • lightness: Number, the brightness component, the range is 0.0-1.0
  • alpha: Number, the transparent component, the range is 0.0-1.0

Return result:

  • Integer, Returns the combined color

hsb

Generate combined colors from hsb color components

1 2 3
static Integer gd.hsb(Number hue, Number saturation, Number brightness);

Call parameters:

  • hue: Number, hue component, the range is 0-360
  • saturation: Number, saturation component, the range is 0.0-1.0
  • brightness: Number, the brightness component, the range is 0.0-1.0

Return result:

  • Integer, Returns the combined color

hsba

Generate combined colors from hsba color components

1 2 3 4
static Integer gd.hsba(Number hue, Number saturation, Number brightness, Number alpha);

Call parameters:

  • hue: Number, hue component, the range is 0-360
  • saturation: Number, saturation component, the range is 0.0-1.0
  • brightness: Number, the brightness component, the range is 0.0-1.0
  • alpha: Number, the transparent component, the range is 0.0-1.0

Return result:

  • Integer, Returns the combined color

color

Generate combined colors from strings

1
static Integer gd.color(String color);

Call parameters:

  • color: String, a character string specifying the color, such as: "#ff0000", "ff0000", "#f00", "f00"

Return result:

  • Integer, Returns the combined color

constant

NONE

Image format constant, indicating that the source of the current image is unknown

1
const gd.NONE = 0;

JPEG

Image format constant, indicating that the current image source is jpeg format data

1
const gd.JPEG = 1;

GIF

Image format constant, indicating that the current image source is gif format data

1
const gd.GIF = 2;

PNG

Image format constant, indicating that the current image source is png format data

1
const gd.PNG = 3;

TIFF

Image format constant, indicating that the current image source is tiff format data

1
const gd.TIFF = 4;

BMP

Image format constant, indicating that the current image source is bmp format data

1
const gd.BMP = 5;

WEBP

Image format constant, indicating that the current image source is webp format data

1
const gd.WEBP = 6;

TRUECOLOR

Image type constant, indicating that the current image is a true color image

1
const gd.TRUECOLOR = 0;

PALETTE

Image type constant, marking the current image as a palette image

1
const gd.PALETTE = 1;

ARC

Fan-shaped drawing style, draw an arc connecting the start and end points

1
const gd.ARC = 0;

CHORD

Fan-shaped drawing style, draw a straight line connecting the origin, start and end points

1
const gd.CHORD = 1;

NOFILL

Fan drawing style, draw a fan without filling

1
const gd.NOFILL = 2;

EDGED

Fan-shaped drawing style, draw an arc connecting the start and end points and a straight line connecting the origin

1
const gd.EDGED = 4;

HORIZONTAL

Mirror direction, mirror image processing horizontally

1
const gd.HORIZONTAL = 1;

VERTICAL

Mirror direction, mirror image processing longitudinally

1
const gd.VERTICAL = 2;

BOTH

Mirror direction, both horizontal and vertical mirror processing

1
const gd.BOTH = 3;

LEFT

Rotation direction, rotate left

1
const gd.LEFT = 1;

Rotation direction, rotate to the right

1
const gd.RIGHT = 2;

MEAN_REMOVAL

Filter type: use average removal method to achieve contour effect

1
const gd.MEAN_REMOVAL = 0;

EDGEDETECT

Filter type: use edge detection to highlight the edges of the image

1
const gd.EDGEDETECT = 1;

EMBOSS

Filter type: emboss the image

1
const gd.EMBOSS = 2;

SELECTIVE_BLUR

Filter type: Blurred image

1
const gd.SELECTIVE_BLUR = 3;

GAUSSIAN_BLUR

Filter type: Blur image with Gaussian algorithm

1
const gd.GAUSSIAN_BLUR = 4;

NEGATE

Filter type: invert all colors in the image

1
const gd.NEGATE = 5;

GRAYSCALE

Filter type: Convert the image to grayscale

1
const gd.GRAYSCALE = 6;

SMOOTH

Filter type: make the image more smooth, use arg1 to set the smoothness level

1
const gd.SMOOTH = 7;

BRIGHTNESS

Filter type: change the brightness of the image, use arg1 to set the brightness level, the value range is -255~255

1
const gd.BRIGHTNESS = 8;

CONTRAST

Filter type: change the contrast of the image, use arg1 to set the contrast level, the value range is 0~100

1
const gd.CONTRAST = 9;

COLORIZE

Filter type: change the hue of the image, use arg1, arg2, and arg3 to specify red, blue, and green respectively. The range of each color is 0~255, arg4 is transparency, and the return value is 0~127

1
const gd.COLORIZE = 10;