Skip to content

Gradient#

This style uses Unicode characters.

Example

Consider the following image:

Apple logo

Apple Computer [Rob Janoff, 1977]

Here's what it should look like:

Apple logo in text (gradient style)

Procedure#

This style is implemented using the GradientDrawer.

Styling

Refer to the procedure outlined in the Styles documentation for an overview of the steps common to all styles.

Initialization#

Charset#

The charset parameter is a string containing characters ordered by their perceived brightness.

Consider the following image:

Slack logo

Slack

Here's what it should look like:

Slack logo in text (default charset)

Slack logo in text (dot charset)

Slack logo in text (hash charset)

Slack logo in text (block charset)

Negative#

The negative parameter controls whether the charset must be reversed.

Consider the following image:

GitHub logo

GitHub

Here's what it should look like:

GitHub logo in text

GitHub logo in text (negative)

Matrices#

The charset_array attribute holds a NumPy ndarray containing all the characters in the charset.

Conversion#

Resizing#

Assuming the output text should have the dimensions text_height and text_width, the image must be resized according to the following criteria:

  • image_height = text_height.
  • image_width = text_width.
  • If either image_height or image_width is 0, it is derived from the other by preserving the aspect ratio of the original image.

Following the above algorithm, each pixel of the resized image will be assigned to one character in the output text.

Source

Refer to the calculate_size function for more information.

Processing#

  1. The resized image is first converted to its grayscale.
  2. The image matrix is normalized such that the grayscale range shifts from (0, 255) to (0, len(charset)).
  3. The charset_array is indexed with the resultant "indices" matrix, giving the final text_matrix.
Processing an image into a text matrix (gradient style)
Source

Refer to the process function for more information.