Encoding and Decoding Sixel Images

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.


rsixel

SIXEL image encoding / decoding for R.

Installation

pak::pak("Fan-iX/rsixel")

You may also need jpeg, png or magick package to read image files.

Usage

SIXEL graphics device

The sixel() function creates a graphics device that outputs SIXEL sequences to the console when closed. This allows you to display plots directly in terminals that support SIXEL graphics.

library(rsixel)
sixel()
plot(iris$Petal.Width, iris$Petal.Length)
dev.off()

The sixel sequence of the plot will be printed to the console after dev.off().

[!NOTE] You need a terminal emulator that support SIXEL graphics format to see the result.

Encoding an image to sixel format

library(rsixel)
image <- png::readPNG("path/to/image.png")
# For example, the R logo from the `png` package:
# image <- png::readPNG(system.file("img", "Rlogo.png", package="png"))
sixel_sequence <- sixelEncode(image, max.colors = 256, iter.max = 10)
cat(sixel_sequence)

A helper function, imgcat, is provided to preview images in R sessions directly.

library(rsixel)
imgcat("path/to/image.png")
# imgcat(system.file("img", "Rlogo.png", package="png"))

png("mpg.png")
ggplot2::qplot(mpg, wt, data = mtcars, colour = cyl)
dev.off()
imgcat("mpg.png")

Decoding sixel sequence to an image

sixel_file <- system.file("snake.six", package="rsixel")
sixel_data <- readChar(sixel_file, file.size(sixel_file))
img <- sixelDecode(sixel_data)

You can also use readSIXEL to read a SIXEL file directly.

img <- readSIXEL(system.file("snake.six", package="rsixel"))

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("rsixel")

0.0.4 by Weifan Lv, 9 months ago


Browse source code at https://github.com/cran/rsixel


Authors: Weifan Lv [aut, cre]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports png

Suggests jpeg, magick


See at CRAN