• home
  • about
  • 全ての投稿
  • ソフトウェア・ハードウェアの設定のまとめ
  • 分析関連のまとめ
  • ヘルスケア関連のまとめ
  • 生涯学習関連のまとめ

sixel

date: 2020-12-20 excerpt: sixel

tag: sixel


sixel

  • terminalで画像を表示するプロトコル
  • 非常にレガシーであるが、iterm2やいくつかのデファクトのターミナルでサポートされている事があり、便利
  • 現在、tmux, moshなどではこのプロトコルのパススルーがサポートされていない
    • mosh上ではコマンドを実行しているのにも関わらず、何も表示されない

install

mac

$ brew install libsixel

ubuntu

$ sudo apt install libsixel-dev libsixel-bin

img2sixel

画像をターミナル上で表示するコマンド

$ img2sixel <image-file>

w3m-sixel

w3mをforkして改造したものを公開している人がいるので、それをコンパイルして利用する

  • link

python-binding

python-bindingを利用すると、pythonから直接terminalに描画できる

install

$ git clone https://github.com/saitoha/libsixel.git
$ cd libsixel
$ ./configure --disable-python
$ make install  # install libsixel
$ cd python
$ python setup.py install 

example

from libsixel.encoder import Encoder as SixelEncoder
from libsixel import SIXEL_OPTFLAG_WIDTH, SIXEL_OPTFLAG_HEIGHT, SIXEL_OPTFLAG_DIFFUSION
from tempfile import NamedTemporaryFile
import time
import sys
import pylab as pl
import numpy as np
try:
    import matplotlib
    matplotlib.use("Agg")
finally:
    pass

def sixeldraw(width=None,height=None):
    x = np.linspace(0,1)

    for i in range(10):
        y = x**i
        pl.plot(x,y)

        with NamedTemporaryFile(prefix="sixel-") as fd:
            pl.savefig(fd,format="png")
            fd.flush()
            encoder = SixelEncoder()
            encoder.setopt(SIXEL_OPTFLAG_DIFFUSION, "atkinson")
            if width : encoder.setopt(SIXEL_OPTFLAG_WIDTH, width)
            if height: encoder.setopt(SIXEL_OPTFLAG_HEIGHT,height)
            print(chr(27) + "[2J")
            encoder.encode(fd.name)
            pl.clf()
        time.sleep(1)

if __name__=="__main__":
    sixeldraw(640*2)


sixel Share Tweet