Skip to main content

image

Description

Draws an image.

This function can be used with different numbers of parameters. The simplest use requires only three parameters: img, x, and y — where (x, y) is the position of the image. Two more parameters can optionally be added to specify the width and height of the image.

This function can also be used with all eight parameters. To differentiate between all these parameters, p8g uses the language of "destination rectangle" (which corresponds to dx, dy, etc.) and "source image" (which corresponds to sx, sy, etc.) below. Specifying the "source image" dimensions can be useful when you want to display a subsection of the source image instead of the whole thing. Here's a diagram to explain further:

image

Syntax

image(img, x, y, [w], [h])
image(img, dx, dy, dw, dh, sx, sy, [sw], [sh])

Parameters

ParameterDescription
imgImage: the image to display
xthe x-coordinate of the top-left corner of the image
ythe y-coordinate of the top-left corner of the image
wthe width to draw the image (Optional)
hthe height to draw the image (Optional)
dxthe x-coordinate of the destination rectangle in which to draw the source image
dythe y-coordinate of the destination rectangle in which to draw the source image
dwthe width of the destination rectangle
dhthe height of the destination rectangle
sxthe x-coordinate of the subsection of the source image to draw into the destination rectangle
sythe y-coordinate of the subsection of the source image to draw into the destination rectangle
swthe width of the subsection of the source image to draw into the destination rectangle (Optional)
shthe height of the subsection of the source image to draw into the destination rectangle (Optional)