jp2a(1) | USER COMMANDS | jp2a(1) |
jp2a - convert JPEG, PNG and WebP images to ASCII
jp2a [ options ] [ filename(s) | URL(s) ]
jp2a will convert JPEG, PNG and WebP images to ASCII characters. You can specify a mixture of files and URLs.
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.
jp2a returns 1 when errors are encountered, zero for no errors.
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 and print:
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, height is automatically calculated from 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 good 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
If you have compiled jp2a with libcurl(3), you can download images by 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 of the downloading, you should use curl(1) or wget(1) and jp2a read the image from standard input.
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.
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 is to use Y = R*0.2989 + G*0.5866 + B*0.1145.
The latest version of jp2a and news is always available from https://github.com/Talinx/jp2a.
cjpeg(1), djpeg(1), jpegtran(1), convert(1), cwebp(1)
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 to 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.
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/
jp2a is distributed under the GNU General Public License v2.
September 22, 2024 | version 1.3.0 |