Module base module

module gd

Image file processing module

base module. Can be used to create and manipulate image files, referenced by:

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, specifies the width of the image
  • height: Integer, specifies the image height
  • color: Integer, specifies the image type, allowed values ​​aregd.TRUECOLORorgd.PALETTE

Return result:

  • Image, returns the successfully created image object

load

Decode image from format data

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

Call parameters:

  • data:Buffer, given the decoded image data

Return result:

  • Image, returns the decoded image object

Decode image from stream object

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

Call parameters:

  • stm:SeekableStream, the stream object where the given image data resides

Return result:

  • Image, returns the decoded image object

Decode an image from the specified file

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

Call parameters:

  • fname: String, specifies the file name

Return result:

  • Image, returns the decoded image object

rgb

Generate combined color from rgb color components

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

Call parameters:

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

Return result:

  • Integer, returns the combined color

rgba

Generate combined color from rgba color components

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

Call parameters:

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

Return result:

  • Integer, returns the combined color

hsl

Generate combined color from hsl color components

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

Call parameters:

  • hue: Number, the hue component, the range is 0-360
  • saturation: Number, saturation component, in the range 0.0-1.0
  • lightness: Number, luminance component, 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, the hue component, the range is 0-360
  • saturation: Number, saturation component, in the range 0.0-1.0
  • lightness: Number, luminance component, range is 0.0-1.0
  • alpha: Number, transparent component, range is 0.0-1.0

Return result:

  • Integer, returns the combined color

hsb

Generate combined color from hsb color components

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

Call parameters:

  • hue: Number, the hue component, the range is 0-360
  • saturation: Number, saturation component, in the range 0.0-1.0
  • brightness: Number, brightness component, 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, the hue component, the range is 0-360
  • saturation: Number, saturation component, in the range 0.0-1.0
  • brightness: Number, brightness component, range is 0.0-1.0
  • alpha: Number, transparent component, 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 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 current image source 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, indicating that the current image is a palette image

1
const gd.PALETTE = 1;

ARC

Fan drawing style, draws an arc connecting the start and end points

1
const gd.ARC = 0;

CHORD

Fan drawing style, draws a straight line connecting the origin, start and end points

1
const gd.CHORD = 1;

NOFILL

Sector drawing style, draws an unfilled sector

1
const gd.NOFILL = 2;

EDGED

Fan drawing style, draws an arc connecting the start and end points and a line connecting the origin

1
const gd.EDGED = 4;

HORIZONTAL

Mirror direction, horizontal mirror processing

1
const gd.HORIZONTAL = 1;

VERTICAL

Mirror direction, do mirroring vertically

1
const gd.VERTICAL = 2;

BOTH

Mirror orientation, both landscape and portrait are mirrored

1
const gd.BOTH = 3;

LEFT

Rotation direction, rotate to the left

1
const gd.LEFT = 1;

Rotation direction, rotate right

1
const gd.RIGHT = 2;

MEAN_REMOVAL

Filter type: use average removal to achieve contouring 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 Image

1
const gd.EMBOSS = 2;

SELECTIVE_BLUR

Filter Type: Blur 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 Image to Grayscale

1
const gd.GRAYSCALE = 6;

SMOOTH

filter type: make the image smoother, set the smoothness level with arg1

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 color tone of the image, use arg1, arg2, arg3 to specify red, blue, green respectively, each color range is 0~255, arg4 is the transparency, the value returned is 0~127

1
const gd.COLORIZE = 10;