https://github.com/mathiasvr/ascii-pixels
🌄 → :symbols: Convert raw image data to ascii art!
https://github.com/mathiasvr/ascii-pixels
ascii-art image-converter
Last synced: 3 months ago
JSON representation
🌄 → :symbols: Convert raw image data to ascii art!
- Host: GitHub
- URL: https://github.com/mathiasvr/ascii-pixels
- Owner: mathiasvr
- License: mit
- Created: 2016-01-11T06:43:31.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2018-10-04T20:30:52.000Z (about 7 years ago)
- Last Synced: 2025-06-26T06:20:00.014Z (4 months ago)
- Topics: ascii-art, image-converter
- Language: JavaScript
- Homepage:
- Size: 28.3 KB
- Stars: 15
- Watchers: 3
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Ascii Pixels [![npm][npm-image]][npm-url]
[npm-image]: https://img.shields.io/npm/v/ascii-pixels.svg
[npm-url]: https://www.npmjs.com/package/ascii-pixelsConvert raw image data to ascii art!
## install
```
npm install ascii-pixels
```## usage
input raw image data, and optionally set contrast or invert colors
```js
var options = {
contrast: 128, // range -255 to +255
invert: true // invert brightness
}var ascii = asciiPixels(imageData, options)
```The raw image data has the following format:
```js
var imageData = {
data: frameData,
width: width,
height: height
}
```
You may optionally provide the pixel format: `imageData.format = 'RGB24'`, by default it is `RGB32`.## examples
Any format is supported as long as you can get the raw image data.
Here are a few examples:### node using jpeg-js
```js
var fs = require('fs')
var jpeg = require('jpeg-js')
var asciiPixels = require('ascii-pixels')var buffer = fs.readFileSync('image.jpg')
var imageData = jpeg.decode(buffer)
var ascii = asciiPixels(imageData)
console.log(ascii)
```### browser using canvas
```js
var asciiPixels = require('ascii-pixels')var img = new Image()
img.onload = function () {
var canvas = document.createElement('canvas')
canvas.width = img.width
canvas.height = img.heightvar context = canvas.getContext('2d')
context.drawImage(img, 0, 0, img.width, img.height)var imageData = context.getImageData(0, 0, canvas.width, canvas.height)
var ascii = asciiPixels(imageData)
console.log(ascii)
}img.src = './nodejs-logo.png'
```### node using canvas
```js
var fs = require('fs')
var Canvas = require('canvas')
var asciiPixels = require('ascii-pixels')var img = new Canvas.Image
img.src = fs.readFileSync('nodejs-logo.png')var canvas = new Canvas(img.width, img.height)
var context = canvas.getContext('2d')context.drawImage(img, 0, 0, img.width, img.height)
var imageData = context.getImageData(0, 0, canvas.width, canvas.height)
var ascii = asciiPixels(imageData)
console.log(ascii)
```## sample output
```
C,
8@@@
0@@@
0@@@
@@ .::. CG 8@@@ G8 ...
t@@@@@@@@1 .:::::::;. @@@@@@@@@@ ,@@@@@@@@; . .
@@@@@ff@@@@@ ::::;;::;::: @@@@@0G@@@@@ @@@@@GG@@@@@ . ..,
@@@@ @@@@ ::::;;:;;;:: 0@@@ 8@@@ 8@@@ ,, @@, . ...
@@@@ @@@@ :::;;;;;;;:: 8@@@t ;@@@@ 8@@@L . ... ,
@@@, :@@@ ,:::;;:::,. i@@@@@@@@@@f ,@@@@@@8 . . ..
,,,: .@@@@; 8@@@ . ,
```## credit
This project is based on the awesome [ascii-camera](https://github.com/idevelop/ascii-camera)
by [Andrei Gheorghe](https://github.com/idevelop)## license
MIT