Socket
Socket
Sign inDemoInstall

bitmap-to-braille

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    bitmap-to-braille

Bitmap to unicode braille converter


Version published
Maintainers
1
Install size
124 kB
Created

Readme

Source

bitmap-to-braille

Bitmap to unicode braille converter

Install

npm i bitmap-to-braille

or

yarn add bitmap-to-braille

Examples

Generate from code

const { bitmapToBraille, CHAR_WIDTH, CHAR_HEIGHT } = require('bitmap-to-braille')

const bitmap = `
  oooo
 o    o
o o  o o
o      o
o o  o o
o  oo  o
 o    o
  oooo
`.replace(/^\n|\n$/g, '').split(`\n`)

console.log(
	bitmapToBraille({
		widthPixels: CHAR_WIDTH * 4,
		heightPixels: CHAR_HEIGHT * 2,
		pixelIsLit: (x, y) => bitmap[y][x] === 'o',
	})
)
/* Output:
⡔⠍⠩⢢
⠣⣑⣊⠜
*/

Generate from image

const { bitmapToBraille, CHAR_WIDTH, CHAR_HEIGHT } = require('bitmap-to-braille')
const Jimp = require('jimp')

Jimp.read('smiley.png')
	.then(img => {
		const width = CHAR_WIDTH * 24
		const ratio = width / img.bitmap.width
		const height = Math.round(img.bitmap.height * ratio / CHAR_HEIGHT) * CHAR_HEIGHT
		return img.resize(width, height).grayscale()
	})
	.then(img => {
		const { width, height, data } = img.bitmap
		console.log(
			bitmapToBraille({
				widthPixels: width,
				heightPixels: height,
				pixelIsLit: (x, y) => data.readUInt8(y * width * 4 + x * 4) <= 127,
			})
		)
	})
	.catch(console.error)
/* Output:
⠀⠀⠀⠀⠀⠀⣀⣤⡴⠶⠚⠛⠛⠓⠶⢦⣤⣀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⢀⣴⠞⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠳⣦⡀⠀⠀⠀
⠀⠀⣰⠟⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣆⠀⠀
⠀⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣧⠀
⢰⡏⠀⠀⠀⠀⢰⣿⠀⠀⠀⠀⣾⡇⠀⠀⠀⠀⠀⠀⠀⠀⢹⡆
⣾⠀⠀⠀⠀⠀⠸⠟⠀⠀⠀⠀⠻⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⣷
⢿⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠀⠀⠀⠀⡿
⠸⣇⠀⠙⢆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡰⠟⠀⠀⠀⣸⠇
⠀⢻⡄⠀⠀⠑⢄⡀⠀⠀⠀⠀⠀⠀⠀⡠⠞⠁⠀⠀⠀⢠⡟⠀
⠀⠀⠹⣦⡀⠀⠀⠉⠓⠲⠤⠤⠖⠒⠉⠀⠀⠀⠀⢀⣴⠏⠀⠀
⠀⠀⠀⠈⠻⢦⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡴⠟⠁⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠉⠛⠳⠶⢤⣤⣤⡤⠶⠞⠛⠉⠀⠀⠀⠀⠀⠀
*/

License

MIT

FAQs

Last updated on 11 Apr 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc