Skip to content

Styles#

Styles refer to the different image processing algorithms that are performed on input images. They affect how images look when viewed in the text form.

Procedure#

Although the different styles use algorithms that produce different results, there are many common, yet fundamental, steps involved in the entire process. Picharsso defines a BaseDrawer that abstracts this general procedure.

Initialization#

This step assigns values to the parameters for the algorithms.

Dimensions#

Picharsso provides control over the dimensions of the output text with the height and width parameters.

Consider the following image:

Zima Blue

Zima Blue [Zima]

Here's what it should look like:

Zima Blue (with height = 32)

Zima Blue (with terminal height)

Zima Blue (with width = 32)

Zima Blue (with terminal width)

Preserving Aspect Ratio

The relationship between height and width preserves the aspect ratio of the input image.

When either one of the dimensions is set as 0, it derives its value from the other.

Error

Assigning 0 to both height and width raises an error. Atleast one of the dimensions must be assigned a non-zero positive integer.

Resampling Filter#

There are instances when an input image must be scaled to an appropriate size before it can be used as input for an algorithm. During this resizing process, pixels must sampled/ resampled to generate the new, resized, image.

Picharsso uses the resampling filters that come with Pillow. The choice of the resampling filter is defined by the resample parameter.

Consider the following image:

Starry Night

Starry Night [Vincent van Gogh, 1889]

Here's what it should look like:

Starry Night (nearest resampling)

Starry Night (box resampling)

Starry Night (bilinear resampling)

Starry Night (hamming resampling)

Starry Night (bicubic resampling)

Starry Night (lanczos resampling)

Note

All resizing operations use the same filter that is set by resample.

Normalization#

Pillow supports multiple image modes. For simplicity, the algorithms were designed to work on the RGB image mode. Hence, images must be converted appropriately.

White Background

A white background is applied to images with the P and RGBA modes.

Source

Refer to the ensure_rgb function for more information.

Conversion#

This step lies at the heart of each style.

Resizing#

Before the image can be processed, it must be resized appropriately. The scale of the resizing depends on the processing algorithm.

Image resizing
Source

Refer to the calculate_size function for more information.

Processing#

The resized image is processed into a text_matrix.

Processing an image into a text matrix
Source

Refer to the process function for more information.

Formatting#

Before it can be displayed, the text_matrix must be formatted into a single string. The type of formatter used is defined by the mode parameter.

Colorization

The formatter requires the original image and the choice of resample filter for pooling colors.

Refer to the colorization step for more information.

Formats

Refer to the Formats documentation to learn about the supported output formats.

Varieties#

All the following styles are implemented using a drawer which inherits from the BaseDrawer.

Consider the following image:

Apple logo

Apple Computer [Rob Janoff, 1977]

Here's what it should look like:

Braille#

The Braille style is implemented using the BrailleDrawer.

Apple logo in text (Braille style)

Gradient#

The gradient style is implemented using the GradientDrawer.

Apple logo in text (gradient style)