image -- Image Object

An image object is a Molt object that wraps an RgbaImage from the image crate and allows it to be manipulated in various ways. The image constructor creates instances of the image object command.

Pixels

Pixels are represented as Molt pixel values; see the pixel command for more details.

Constructor

Syntax: image name width height

The image command creates an image object, a Molt binding to a Rust RgbaImage struct. The new image object is a Molt command called name; the command provides access to the newly created image, which will have the given width and height in pixels. Returns the name.

The image will initially be full of transparent pixels: #000000.00.

$ image myimage 32 32
myimage
$ myimage width
32
$ myimage height
32
$

Object Command

Syntax: image subcommand ?args...?

The image object command has the following subcommands.

SubcommandDescription
image clearClears an image to a given color
image dumpDumps the pixel content to stdout
image getGets a pixel from the image
image heightAn image's height in pixels
image putSets a pixel in the image
image saveSaves the image to disk
image widthAn image's width in pixels

image clear


Syntax: image clear ?fill?

Clears the image's pixels by setting them to the given fill color, which must be a pixel value. The fill defaults to white, #FFFFFF.

$image clear #000000    ;# Clear to black
$image clear #000000.00 ;# Clear to transparent

image dump


Syntax: image dump

Dumps the image's pixels to standard output, one pixel per row. Used for debugging.

$ image fred 16 16
fred
$ image dump
[0,0]: Rgba([0, 0, 0, 0])
[0,1]: Rgba([0, 0, 0, 0])
[0,2]: Rgba([0, 0, 0, 0])
...

image get


Syntax: image get x y

Gets the pixel at the given (x,y) coordinates.

$ $image get 10 15
#123456

image height


Syntax: image height

Returns an image's height in pixels.

image put


Syntax: image put x y ?pixel?

Sets the pixel at the given (x,y) coordinates to the given pixel value, which defaults to black, #000000.

$image put 10 15 #0000FF   ;# Set pixel at 10,15 to blue

image save


Syntax: image save filename

Attempts to save the the image to the given file. The image type is determined by the image crate from the file's file type.

image width


Syntax: image width

Returns an image's width in pixels.