Skip to main content

Turns images into ASCII art. This is just the core library; make sure to install some extras, too.

Project description

image2ascii-core

thisprojectwascodedbyahumanbeing-wordart

This is a thing that makes fancy ANSI graphics out of image files. And not just by sloppily repeating the same character all over the place; no, it detects transparency and draws edges with .od$$o.o$$bo. etc, like a real little ANSI artist.

It's an almost complete rewrite of an old project of mine. It's pretty versatile. You can adjust sizes, colour balance, contrast, define your own colour converters, shape sets, etc.

There is a CLI tool in a separate repo. More info will probably come soon.

image

Optimization/benchmarking

Image resizing methods

Benchmarking the different PIL.Image.Resampling methods when downsizing an 1833x1380 image to 18x13:

NEAREST: 3.05 μs ± 50.6 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
BOX: 3.93 ms ± 48.8 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
HAMMING: 7.28 ms ± 24 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
BILINEAR: 7.3 ms ± 137 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
BICUBIC: 13.3 ms ± 43.2 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)
LANCZOS: 19.5 ms ± 34.2 μs per loop (mean ± std. dev. of 7 runs, 100 loops each)

(NEAREST is more than a thousand times faster than the runner-up!)

And when upsizing the same image to 18300x13800:

NEAREST: 696 ms ± 11.5 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
BOX: 1.75 s ± 11.7 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
BILINEAR: 2.13 s ± 48.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
HAMMING: 2.13 s ± 16.6 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
BICUBIC: 2.88 s ± 14.4 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)
LANCZOS: 3.69 s ± 121 ms per loop (mean ± std. dev. of 7 runs, 1 loop each)

(Just a 2.5x lead for NEAREST here.)

Image section colour inference methods

Inferring colour for an RGBA array of shape=(29, 4):

MEDIAN: 2.11 μs ± 29.1 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
MOST_COMMON: 25.4 μs ± 910 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each)

ColorInferenceMethod.MEDIAN is more than 10x faster.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

image2ascii_core-0.8.0.tar.gz (248.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

image2ascii_core-0.8.0-py3-none-any.whl (253.0 kB view details)

Uploaded Python 3

File details

Details for the file image2ascii_core-0.8.0.tar.gz.

File metadata

  • Download URL: image2ascii_core-0.8.0.tar.gz
  • Upload date:
  • Size: 248.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for image2ascii_core-0.8.0.tar.gz
Algorithm Hash digest
SHA256 b1bc0941344e56436197998611d643a327a21c39c6b6f948e7422d6047e21fca
MD5 01e534c5e1d3c8ce40d7e7d00bf0eb9d
BLAKE2b-256 a1c47b29798deae97ec8db1b1357be517e0201917c3e2d9244fffb55dcf970a0

See more details on using hashes here.

File details

Details for the file image2ascii_core-0.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for image2ascii_core-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6df9b5093d3ac150e267c5d5c5a6780781f7bb9d8a4e96be9fa358e269e9790
MD5 ccd9a239f43278787accfb97ea0af098
BLAKE2b-256 e9fdb9854ab2ccb92ab3e12d0f44081dd75ab95f2072f9da5ab5981422925459

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page