bimg
An API that draws and manipulates .bimg images.
new(path, binary) | Instantiate a new Image object. |
---|
- new(path, binary)Source
Instantiate a new Image object.
Parameters
- path string Path to the image.
- binary boolean Whether or not the image was written in binary mode.
Returns
- Image the new image object.
Types
Image
The image object. Contains functions for drawing, and extracting metadata. Created by {@new}.
- Image.draw(x, y, Options)Source
Draw the image. If this is an animated image in between each frame it will call
sleep
. This will not reset cursor position!Parameters
- x number X coordinate to draw the image at.
- y number Y coordinate to draw the image at.
- Options { window? = table, transparency? = boolean }
that control how the image is drawn.
window
: A window object to draw to. This is so that transparency can be supported. If this is not passed, we will see ifterm.current().getLine
exists. If it does not, then transparency will not be supported, and will be replaced by black. If a window object is provided then this will draw to that, and callwindow.setVisible
as appropriate to make the image draw better. Otherwise it will just direct callterm
. It will still call window functions even iftransparency
is false.transparency
: Even if transparency is supported, if this isfalse
then it will be replaced by black. Setting this to true can not force transparency to work.term
: The terminal to draw to, defaults to regular terminal.
- Image:getMetadata()Source
Retrieve the metadata of the image. This returns a table of all of the metadata in the bimg format. :::info This will also return custom keys, that are not part of the spec. ::: @treturn table Metadata of the image.
- Image:setMetadata(metadata)Source
Set the metadata of the image. This takes a table (Usually one returned by image:draw, but can be custom made), and writes in the keys (Basically a shallow clone) to the image. This will then save the image to a file. :::info Custom metadata keys can be added, and it will not complain, but note that other programs might not see these keys, or do anything with them. ::: :::caution This will only write string keys, and will ignore function, table, number, etc. keys. ::: @tparam table metadata Metdata information.
Parameters
- metadata
- Image.clearMetadata()Source
This clears the metadata, useful to completely overwrite metadata. It also returns a copy of the removed metadata.
Returns
- table Old metadata of the image.
- Image.setPixel(...)Source
Set a pixel at a specific point.
Parameters
- x number X coordinate of the pixel.
- y number Y coordinate of the pixel.
- char string Character to place.
- fg string | number Foreground colour. Accepts either a blit colour or
colours
colour. - bg string | number Background colour. Accepts either a blit colour or
colours
colour. - frame number Frame to set, defaults to 1.
Or
- Image.setLine(...)Source
Set a line of characters.
Parameters
- y number Y coordinate of the line.
- char string Characters to set.
- fg string Foreground blit colour.
- bg string Background blit colour.
- frame number Frame to set, defaults to 1.
Or
- Image.getPixel(x, y [, frame])Source
Get a pixel.
Parameters
- x number X coordinate of the pixel.
- y number Y coordinate of the pixel.
- frame? number Frame to get, defaults to 1.
Returns
- string Character of the pixel.
- string Foreground colour of the pixel.
- string Background colour of the pixel.
Or
- nil Pixel does not exist in the image.
- Image.getLine(y [, frame])Source
Get a line.
Parameters
- y number Y coordinate of the line.
- frame? number Frame to get, defaults to 1.
Returns
- string Characters of the line.
- string Foreground colours of the line.
- string Background colours of the line.
Or
- nil Line does not exist in the image.
- Image.resize(method)Source
Resize the image.
Parameters
- method string
Method used to resize the image. Valid methods are:
"black"
: Fills in empty space with just black characters."repeat"
: Repeats the last row/column data for the empty space."transparent"
: Fills the empty space with completely invisible characters.
- method string
- Image:reload()Source
Refresh the image from the file. This simply reads the file again.
- Image.save([path])Source
Save the image to the file.
Parameters
- path? string A new path to save to. Defaults to the original path of the image.