API

taggon edited this page May 25, 2011 · 6 revisions
Clone this wiki locally

For exact documentation, see GD reference.

Overview

Creation methods return new Image object which is represented by image.
image is an instance of Image object.
Most of Image’s methods return self object, so you can use function chaning like this:

var black = image.colorAllocate(0,0,0);
image.line(0,0,10,20,black).filledRectangle(10,20,50,60,black);

Creation

openJpeg

Image openJpeg(filepath) // synchronous way
void  openJpeg(filepath, callback) // asynchronous way

openPng

Image openPng(filepath)
void  openPng(filepath, callback)

openGif

Image openGif(filepath)
void  openGif(filepath, callback)

openGd

Image openGd(filepath)
void  openGd(filepath, callback)

openGd2Part

Image openGd2Part(filepath, srcX, srcY, width, height)
void  openGd2Part(filepath, srcX, srcY, width, height, callback)

openWBMP

Image openWBMP(filepath)
void  openWBMP(filepath, callback)

create

Image create(width, height)

createTrueColor

Image createTrueColor(width, height)

createFromJpeg

Image createFromJpeg(filepath)

createFromJpegPtr

Image createFromJpegPtr(data)

createFromPng

Image createFromPng(filepath)

createFromPngPtr

Image createFromPngPtr(data)

createFromGif

Image createFromGif(filepath)

createFromGifPtr

Image createFromGifPtr(data)

createFromGd2

Image createFromGd2(filepath)

createFromGd2Ptr

Image createFromGd2Ptr(data)

createFromGd2Part

Image createFromGd2Part(filepath, srcX, srcY, width, height)

createFromGd2PartPtr

Image createFromGd2Part(data, srcX, srcY, width, height)

createFromWBMP

Image createFromWBMP(filepath)

createFromWBMPPtr

Image createFromWBMPtr(data)

Drawing

setPixel

Image image.setPixel(x, y, color)

line

Image image.line(x1, y1, x2, y2, color)

Draw a line between two endpoints(x1,y1 and x2,y2).

var black = image.colorAllocate(0, 0, 0);
image.line(0, 0, 100, 100);

dashedLine

Image image.dashedLine(x1, y1, x2, y2, color)

Draw a dashed line between two endpoints(x1,y1 and x2,y2).

polygon

Image image.polygon(points, color)

Draw a polygon with the array of points(at least 3).

var points = [
  {x:0, y:100},
  {x:100, y:100},
  {x:0, y:100}
];
image.polygon(points, black);

filledPolygon

Image image.filledPolygon(points, color);

Draw a filled polygon with the array of points(at least 3).