Skip to content
wvanbergen edited this page Feb 25, 2011 · 4 revisions

Currently, the drawing API are rather limited. Feel free to send in patches.

Coordinates

ChunkyPNG bases its coordinate system on how images are encoded. This means, that the top left pixel has coordinates (0, 0). The bottom-left right has coordinates (width – 1, height – 1). Graphical:

(0,0)        .         (sx-1,0)

.                             .

(0,sy-1)     .      (sx-1,sy-1)

Drawing methods

Drawing operations are defined in the ChunkyPNG::Canvas::Drawing module, which is included in the Canvas class.

ChunkyPNG::Canvas#compose_pixel ( x, y, color )

Sets a point on the canvas, by blending the given color with the background color using alpha composition.

ChunkyPNG::Canvas#line (x0, y0, x1, y1, color )

Draws an anti-aliased line from point 0 to point 1 in the given color.

ChunkyPNG::Canvas#rect (x0, y0, x1, y1, stroke_color, fill_color )

ChunkyPNG::Canvas#circle (x0, y0, radius, stroke_color, fill_color )

ChunkyPNG::Canvas#polygon (points, stroke_color, fill_color )

Canvas operations

Canvas operations are defined in the ChunkyPNG::Canvas::Operations module, which is included in the Canvas class. All the methods without a bang will return a new canvas instance. Add a bang to make them do their work in place.

ChunkyPNG::Canvas#compose ( other_canvas, x = 0, y = 0 )

Composes the other_canvas over the current canvas, using alpha composition.

ChunkyPNG::Canvas#replace ( other_canvas, x = 0, y = 0 )

Replaces current pixels by pixels from the other_canvas.

ChunkyPNG::Canvas#crop ( x, y, crop_width, crop_height )

Slices a new canvas of the given size out of the current canvas. Returns a new canvas object, leaving the current canvas intact.