Converts JPG picture into ASCII symbols. The project was build with JavaScript.
To run this project on your own machine follow these steps:
- Clone this repository with
git clone https://github.com/zaxoavoki/jpg-to-ascii.git
- Install all dependencies with
npm install
- Run
npm run build
andnpm run start
or simplynpm run dev
or check it out here.
I have used jpeg-js
library to read image data. The sRGB (stardard Reg Green Blue) color space is defined in terms of the CIE 1931 linear luminance Ylin, which is given by:
Ylin = 0.2126 Rlin + 0.7152 Glin + 0.0722 * Blin
After mapping each pixel to grayscale with this formula (e.g. rgba(255, 255, 255, 0) => 254.998
) I have replaced given value with most suitable one in ascii_map.json
.
To make an image smaller I have used an algorithm that just removes every second row or column (depends on what we resize - height or width).
To get number of squeeze times I used tricky formula 2^x = width / 170px
.
- Add extended ASCII map
- Add support for other image formats