Simple library to convert an image to a text file. Some techniques were borrowed from this article.
This was created for p2r3's convert but can be used independently.
To run the application, do:
deno run --allow-read src/app.ts <image name>The text version is outputted to STDOUT.
This repository can be included as a git submodule or by other means, then:
import { imageToText } from "/path/to/image-to-txt/convert.ts";
const str = imageToText({
width() { ... },
height() { ... },
getPixel(x: number, y: number) { ... }
})
// str contains the returned textA font atlas must be placed at ./assets/atlas.png; this should be an image
containing all ASCII characters horizontally. This repository contains one by
default. Then, you should run deno run src/generate.ts; this will create
src/generated.ts which will contain the font data necessary for creating an
image.
Contributions welcome. However, do not contribute on the GitHub repository - any PRs or issues there will be closed.
Please use the mailing list on the sourcehut repository to send patches and bug reports.
Needs to be optimized; performance is currently very bad.
Could implement better contrast as suggested by the linked blogpost.