| Title: | Encoding and Decoding Sixel Images |
|---|---|
| Description: | Provides a native R implementation for encoding and decoding 'sixel' graphics (<https://vt100.net/docs/vt3xx-gp/chapter14.html>), and a dedicated 'sixel' graphics device that allows plots to be rendered directly within compatible terminal emulators. |
| Authors: | Weifan Lv [aut, cre] |
| Maintainer: | Weifan Lv <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.0.4 |
| Built: | 2026-05-21 06:00:07 UTC |
| Source: | https://github.com/cran/rsixel |
Create SIXEL escape sequence for image file. jpeg, png or magick packages
are required to read image files. Image with alpha channel will be blended with
the specified background color.
imgcat( path, ..., max.colors = 256, iter.max = 10, background = "white", file = "" )imgcat( path, ..., max.colors = 256, iter.max = 10, background = "white", file = "" )
path |
character, path to a image file. |
... |
other positional arguments will be omitted. |
max.colors |
integer, max colors of the palette. The maximum is 256.
This parameter will be passed to |
iter.max |
integer, maximum number of iterations for k-means clustering.
This parameter will be passed to |
background |
character, background color to blend with for pixel with transparency. Default is "white". |
file |
A connection, or a character string naming the file to print to.
This parameter will be passed to |
None (invisible 'NULL').
imgcat(system.file("img", "Rlogo.jpg", package="jpeg"))imgcat(system.file("img", "Rlogo.jpg", package="jpeg"))
Reads an image from a SIXEL file into a raster array.
readSIXEL(source)readSIXEL(source)
source |
character, name of the file to read from. |
A raster array with values ranging from 0 to 1. The array has dimensions (height, width, 3) where the third dimension represents the R, G, and B color channels.
# read a sample file img <- readSIXEL(system.file("snake.six", package="rsixel"))# read a sample file img <- readSIXEL(system.file("snake.six", package="rsixel"))
A graphics device that outputs SIXEL sequences to the console when closed. This device wraps the png() device and encodes the output as SIXEL.
sixel( file = "", width = 480, height = 480, max.colors = 256, iter.max = 10, background = "white", ... )sixel( file = "", width = 480, height = 480, max.colors = 256, iter.max = 10, background = "white", ... )
file |
A connection, or a character string naming the file to print to.
This parameter will be passed to |
width |
integer, width of the output image in pixels. Default is 480. |
height |
integer, height of the output image in pixels. Default is 480. |
max.colors |
integer, max colors of the palette. The maximum is 256.
This parameter will be passed to |
iter.max |
integer, maximum number of iterations for k-means clustering.
This parameter will be passed to |
background |
character, background color to blend with for pixel with transparency. Default is "white". |
... |
Additional arguments passed to |
The device number (invisible).
sixel() plot(c(1, 2)) dev.off()sixel() plot(c(1, 2)) dev.off()
Parse a SIXEL escape sequence and convert it to a raster array.
sixelDecode(data)sixelDecode(data)
data |
character, SIXEL escape sequence. |
A raster array with values ranging from 0 to 1. The array has dimensions (height, width, 3) where the third dimension represents the R, G, and B color channels.
# read sixel sequence sixel_file <- system.file("snake.six", package="rsixel") sixel_data <- readChar(sixel_file, file.info(sixel_file)$size) img <- sixelDecode(sixel_data)# read sixel sequence sixel_file <- system.file("snake.six", package="rsixel") sixel_data <- readChar(sixel_file, file.info(sixel_file)$size) img <- sixelDecode(sixel_data)
Create SIXEL escape sequence from image data. Quantization is done by k-means clustering.
sixelEncode(image, max.colors = 256, iter.max = 10)sixelEncode(image, max.colors = 256, iter.max = 10)
image |
a three dimensional RGB array with values ranging from 0 to 1. |
max.colors |
integer, max colors of the palette. The maximum is 256. Default is 256. |
iter.max |
integer, maximum number of iterations for k-means clustering. |
SIXEL escape sequence
img <- png::readPNG(system.file("img", "Rlogo.png", package="png")) cat(sixelEncode(img, 4))img <- png::readPNG(system.file("img", "Rlogo.png", package="png")) cat(sixelEncode(img, 4))