Send Images To Your Terminal With Rich Pixels

[darrenburns]’ Rich Pixels is a library for sending colorful images to a terminal. Give it an image, and it’ll dump it to your terminal in full color. While it also supports ASCII art, the cool part is how it makes it so easy to display an arbitrary image — a pixel-art rendition of it, anyway — in a terminal window.

How it does this is by cleverly representing two lines of pixels in the source image with a single terminal row of characters. Each vertical pixel pair is represented by a single Unicode ▄ (U+2584 “lower half block”) character. The trick is to set the background color of the half-block to the upper pixel’s RGB value, and the foreground color of the half-block to the lower pixel’s RGB. By doing this, a single half block character represents two vertically-stacked pixels. The only gotcha is that Rich Pixels doesn’t resize the source image; if one’s source image is 600 pixels wide, one’s terminal is going to receive 600 U+2584 characters per line to render the Rich Pixels version.

[Simon WIllison] took things a step further and made show_image.py, which works the same except it resizes the source image to fit one’s terminal first. This makes it much more flexible and intuitive.

The code is here on [Simon]’s tools GitHub, a repository for software tools he finds useful, like the Incomplete JSON Pretty Printer.

10 thoughts on “Send Images To Your Terminal With Rich Pixels

    1. Well, with sixtels (2×3 subpixels) (or even braille code, giving you 2×4 subpixels), you are still limited to two colors.
      So, you first have to chose which color most represent the block of pixels you want to display.
      But it’s indeed not new nor performant to use half blocks to display images.
      Even Cacalib does a finer job than that.
      Still a funny reminder of what can be done tho.

    2. Oh sorry, I though you were talking about the unicode “Symbols for Legacy Computing” page, containing the 2×3 pseudo graphical blocks from Teletexte…
      For more unicode goodness, the “Block Elements” page, gives you “Quadrant” 2×2 subpixel glyphs
      And as previously stated, “Braille Patterns” page would give you 2×8 sub pixels glyphs
      But each glyph can only have 2 colors, whatever the number of sub pixels.

Leave a Reply to Daniel Scott MatthewsCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.