npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

textifier

v1.2.0

Published

Convert images to text in your browser

Downloads

7

Readme

Textifier

Textifier is a javascript library that lets you convert images to any text of your choosing, in your browser

| Original | Colored | Grayscale | Monochrome | Console | | --- | --- | --- | --- | --- | | Original | Colored | Grayscale | Monochrome | Console |

Textifier can print as HTML an image or it can even print it in you browser's console.

Instalation

$ npm install textifier
# OR
$ bower install textifier

Or just download the minified script and add it in your HTML:

<script src="textifier.min.js"></script>

Usage

Here is the mandatory one-liner to show how simple it can be.

new Textifier().draw(target, 'images/piggies.png');

Of course you are probably going to want use some options. Textifier takes 3 optional arguments: maxWidth, maxHeight and options.

:warning: NOTES :warning:

Textifier needs CORS access to the source images.

maxWidth

type: number | string

maxWidth should be a positive number. This sets maximum width of the rendered image. If it is not set or set with an invalid value, it will take as much space as it can.

Valid values are either a number or a valid CSS size value (e.g 200px).

Unless specified units will be measured in characters.

maxHeight

type: number | string

Same as maxWidth except that if it is not set the maximum height will be the the same as the height of the original image but in characters instead of pixels.

options

type: object

Every other option will be in the option object.

| Names | Defaults | Types | Info | --- | --- | --- | --- | characters | "01" | string | The character list to write the image with. | background | #00000000 | string | Color of the background. This color will also be rendered in text. | ordered | false | boolean | If true the characters will show up in order of the characters string | color | 0 | number | If the image should be colored, in grayscale or monochrome0 = colored1 = grayscale2 = monochromeTextifier comes with some constants so you don't have to memorize this

Since all arguments are optional the options argument can be placed anywhere by omitting any of the other 2.

new Textifier(100, 50, options);
new Textifier(100, options);
new Textifier(options);

↿These are all valid↾

Functions

There are 3 main functions in Textifier, write, draw and log. There a few other mainly used internally but available anyways since they might come in handy.

write, draw

arguments: (url, element, append)

The write and draw functions work exactly the same way. The only difference is that write will print html in a <pre> tag and the draw will print an actual image on a canvas.

url

type: string

The url of the image to be used.

element

type: DOM Element

The element in which the rendered image will be added to.

append

type: boolean

If the rendered image should be appended or replace the contents of the target element.

Example
new Textifier(100, {characters: 'oink', ordered: true}).draw('images/piggies.png', target);
Output

Rendered image

log

arguments: (url)

The log function will print the image in the dev console of your browser.

url

type: string

The url of the image to be used.

Example
new Textifier(100, {characters: 'oink', ordered: true}).log('images/piggies.png');
Output

Rendered image

Constants

Textifier comes with some "constants" so you don't have to remember arguments that are numbers and to make your code more readable.

Textifier.COLORED = 0;
Textifier.GRAYSCALE = 1;
Textifier.MONOCHROME = 2;

Textifier.HTML = 0;
Textifier.CANVAS = 1;
Textifier.CONSOLE = 2;

License

MIT License