jp2a(1)

πŸ“¦
version 1.3.3 Β· 2 versions
, in arch rolling, debian trixie, nixos 26.05, nixpkgs unstable, opensuse-leap 16.0, ubuntu resolute, ubuntu stonking

🌸 NAME 🌸

jp2a β€” converts JPEG, PNG and WebP images into ASCII. that's it, that's the whole serve πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

jp2a [ options ] [ filename(s) | URL(s) ]

πŸ’– DESCRIPTION πŸ’–

okay so bestie, jp2a takes your JPEG, PNG and WebP images and turns them into ASCII characters. iconic behaviour honestly. and the cute part? you can hand it a mixture of files and URLs in the same command, no cap. ✨


πŸ‘‘ OPTIONS πŸ‘‘

  • - β€” reads a JPEG, PNG or WebP image straight from standard input 🫢
  • --background=light, --background=dark β€” if you're tired of fiddling with --invert every single time, just use these instead. white characters on a black display? that's --background=dark. the other way round? --background=light. easy πŸ’…
  • -b, --border β€” frames your output image in a border πŸŽ€
  • --chars=... β€” use these characters when producing the output ASCII image. the default is " ...',;:clodxkO0KXNWM" ⭐
  • --colors β€” uses truecolor (or ANSI color if truecolor isn't supported) for text output, and CSS color for HTML output 🌈
  • --color-depth=... β€” use a specific color-depth for terminal output. valid values are: 4 (for ANSI), 8 (for 256 color palette) and 24 (for truecolor or 24-bit color) 🎨
  • -d, --debug β€” prints debugging info when using libcurl to download images off the net πŸ”
  • -f, --term-fit β€” uses the largest dimension that makes the image fit in your terminal display πŸ“
  • --term-height β€” uses the terminal display height and calculates the width based on the image's aspect ratio πŸ“
  • --term-width β€” uses the terminal display width and calculates the height based on the image's aspect ratio πŸ“
  • -z, --term-zoom β€” uses the terminal display width and height πŸ–₯️
  • -c, --term-center β€” centers the image in your terminal 🎯
  • --fill β€” when used with --html and --color, it colors each output character's background color. for instance, if you wanna use fill-output on a light background, do:
jp2a --color --html --html-fill --background=light somefile.jpg
--output=dark.html

to do the same on a light background:

jp2a --color --html --html-fill --background=dark somefile.jpg
--output=light.html

the default is to have fill disabled πŸ™ˆ

  • -x, --flipx β€” flips the output image horizontally ↔️
  • -y, --flipy β€” flips the output image vertically ↕️
  • --height=N β€” sets the output height. if you only specify --height, then the output width gets calculated according to the source image's aspect ratio πŸ“
  • -h, --help β€” displays a short help text πŸ’¬
  • --grayscale β€” converts the image to grayscale when using --html or --colors 🩢
  • --html β€” makes ASCII output in strict XHTML 1.0. (will output in HTML for version 2.0.0 and above.) 🌐
  • --htmlls β€” makes ASCII output in HTML (Living Standard), suitable for viewing with web browsers. this is useful with big output dimensions, and if you wanna check the result with a browser with a small font πŸ”Ž
  • --xhtml β€” makes ASCII output in strict XHTML 1.0 πŸ“„
  • --html-fill β€” same as --fill. you should use that option instead 🫢
  • --html-no-bold β€” do not use bold text for HTML output 🚫
  • --html-raw β€” outputs only the image in HTML codes, leaving out the rest of the webpage, so you can construct your own. (will use <br> for version 2.0.0 and above instead of <br/>.) 🧱
  • --html-fontsize=N β€” sets the fontsize when using --html output. the default is 4 πŸ” 
  • --html-title=... β€” sets the HTML output title ✏️
  • --output=... β€” writes ASCII output to the given filename. to explicitly specify standard output, use --output=- πŸ’Ύ
  • -i, --invert β€” inverts the output image. if you're viewing a picture with a white background, but you're on a display with light characters on a dark background, you should invert the image πŸ”„
  • --red=..., --green=..., --blue=... β€” when converting from RGB to grayscale, these are the weights used to calculate luminance. the default is red=0.2989, green=0.5866 and blue=0.1145 🌈
  • --size=WIDTHxHEIGHT β€” sets the output dimension πŸ“¦
  • -v, --verbose β€” prints some verbose information to standard error when reading each JPEG image πŸ—£οΈ
  • --width=N β€” sets the output width. if you only specify the width, the height gets calculated automatically πŸ“
  • -V, --version β€” prints the program version 🏷️
  • --zoom β€” sets output dimensions to your entire terminal window, disregarding the source image's aspect ratio πŸ”
  • --edge-threshold=... β€” specifies an image gradient above which to shade lines and edges with directional glyphs (such as -/|\). the right value to pick up the edges nicely will depend on the image, but it might be around 0.5 ✏️
  • --edges-only β€” only draws edges, so that the resulting image is like a line drawing or edge detector. this option should be used in conjunction with --edge-threshold so that edges are drawn ✍️

πŸŽ€ RETURN VALUES πŸŽ€

jp2a returns 1 when errors are encountered, and zero for no errors. simple as that 🫢


🌟 EXAMPLES 🌟

convert and print imagefile.jpg using ASCII characters in 40 columns and 20 rows:

jp2a --size=40x20 imagefile.jpg

download an image off the net, convert it and print it:

jp2a http://www.google.com/intl/en/logos/easter_logo.jpg

output picture.jpg and picture2.jpg, each 80x25 characters, using the characters " ...ooxx@@" for output:

jp2a --size=80x25 --chars=" ...ooxx@@" picture.jpg picture2.jpg

output image.jpg using 76 columns, with the height automatically calculated from the aspect ratio of image.jpg:

cat image.jpg | jp2a --width=76 -

if you use jp2a together with ImageMagick's convert(1), then you can make great use of pipes and have ImageMagick do all sorts of image conversions and effects on the source image. for example:

magick somefile.gif jpg:- | jp2a - --width=80

check out convert(1) options to see what you can do. Convert can handle almost any image format, so with this combination you can convert images in e.g. PDF or AVI files to ASCII. 🀯

jp2a uses a very basic scaling algorithm for every image format except WebP. to get better quality, convert an image to WebP to make use of the scaling built into the libwebp library:

cwebp -quiet image.jpg -o - | jp2a -

although the default build of jp2a includes automatic downloading of files specified by URLs, you can explicitly download them by using curl(1) or wget(1), for example:

curl -s http://foo.bar/image.jpg | magick - jpg:- | jp2a -

you can pass the --edge-threshold option to highlight the edges of the image, or add the --edges-only option to draw only the edges, to produce a line drawing:

jp2a --edge-threshold=0.5 --edges-only imagefile.jpg

🌐 DOWNLOADING IMAGES FROM THE NET 🌐

if you compiled jp2a with libcurl(3), you can download images by just specifying URLs:

jp2a https://user:pass@foo.com/bar.jpg

the protocols recognized are ftp, ftps, file, http, https and tftp πŸ“‘

if you need more control over the downloading, you should use curl(1) or wget(1) and have jp2a read the image from standard input instead.

jp2a uses pipe and fork to download images using libcurl (i.e., no exec or system calls), and therefore does not worry about malevolently formatted URLs. she's unbothered, moisturised, in her lane πŸ’…βœ¨


🩢 GRAYSCALE CONVERSION 🩢

you can extract the red channel by doing this:

jp2a somefile.jpg --red=1.0 --green=0.0 --blue=0.0

this will calculate luminance based on Y = R*1.0 + G*0.0 + B*0.0. the default values are to use Y = R*0.2989 + G*0.5866 + B*0.1145 🌈


🏠 PROJECT HOMEPAGE 🏠

the latest version of jp2a and news is always available from https://github.com/Talinx/jp2a πŸ‘‘


πŸ”— SEE ALSO πŸ”—

cjpeg(1), djpeg(1), jpegtran(1), convert(1), cwebp(1)


πŸ’€ BUGS πŸ’€

jp2a does not interpolate when resizing (except for WebP images). if you want better quality, try using cwebp(1) to convert the image to WebP before using jp2a, so you get correct scaling 😭

another issue is that jp2a skips some X-pixels along each scanline. this gives a less precise output image, and will probably be corrected in future versions πŸ™ˆ


πŸ’œ AUTHOR πŸ’œ

Christian Stigen Larsen and Christoph Raitzig πŸ‘‘

jp2a uses jpeglib to read JPEG files. jpeglib is made by The Independent JPEG Group (IJG), who have a page at http://www.ijg.org

jp2a uses libpng to read PNG files. libpng's homepage: http://libpng.org/pub/png/libpng.html

jp2a uses libwebp to read WebP files. libwebp's homepage: https://developers.google.com/speed/webp/


πŸ“œ LICENSE πŸ“œ

jp2a is distributed under the GNU General Public License v2 βš–οΈ


and that's a wrap bestie!! πŸ’– this whole thing is version 1.3.0, dated September 22, 2024 β€” go forth and asciify everything, you absolute icon βœ¨πŸŽ€πŸ¦‹