bimg
An API that draws and manipulates .bimg images.
| new(path, binary) | Instantiate a new Image object. |
|---|
- new(path, binary)Source
Instantiate a new
Imageobject.Parameters
- path
stringPath to the image. - binary
booleanWhether or not the image was written in binary mode.
Returns
Imagethe new image object.
- path
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
numberX coordinate to draw the image at. - y
numberY 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().getLineexists. 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.setVisibleas appropriate to make the image draw better. Otherwise it will just direct callterm. It will still call window functions even iftransparencyis false.transparency: Even if transparency is supported, if this isfalsethen 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.
- x
- 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
tableOld metadata of the image.
- Image.setPixel(...)Source
Set a pixel at a specific point.
Parameters
- x
numberX coordinate of the pixel. - y
numberY coordinate of the pixel. - char
stringCharacter to place. - fg
string|numberForeground colour. Accepts either a blit colour orcolourscolour. - bg
string|numberBackground colour. Accepts either a blit colour orcolourscolour. - frame
numberFrame to set, defaults to 1.
Or
- x
- Image.setLine(...)Source
Set a line of characters.
Parameters
- y
numberY coordinate of the line. - char
stringCharacters to set. - fg
stringForeground blit colour. - bg
stringBackground blit colour. - frame
numberFrame to set, defaults to 1.
Or
- y
- Image.getPixel(x, y [, frame])Source
Get a pixel.
Parameters
- x
numberX coordinate of the pixel. - y
numberY coordinate of the pixel. - frame?
numberFrame to get, defaults to 1.
Returns
stringCharacter of the pixel.stringForeground colour of the pixel.stringBackground colour of the pixel.
Or
- nil Pixel does not exist in the image.
- x
- Image.getLine(y [, frame])Source
Get a line.
Parameters
- y
numberY coordinate of the line. - frame?
numberFrame to get, defaults to 1.
Returns
stringCharacters of the line.stringForeground colours of the line.stringBackground colours of the line.
Or
- nil Line does not exist in the image.
- y
- Image.resize(method)Source
Resize the image.
Parameters
- method
stringMethod 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
- 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?
stringA new path to save to. Defaults to the original path of the image.
- path?