# text2png

> Convert text to png for node.js

Latest version **2.3.0** (published 2019-10-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install text2png
pnpm add text2png
yarn add text2png
bun add text2png
```

Provides the command `text2png`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.3.0 |
| Published | 2019-10-19 |
| First published | 2016-04-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 194 |
| Author | tkrkts |
| Maintainers | tkrkt |
| Keywords | text, png |

## Links

- npm: https://www.npmjs.com/package/text2png
- Repository: https://github.com/tkrkt/text2png
- Homepage: https://github.com/tkrkt/text2png#readme
- Issues: https://github.com/tkrkt/text2png/issues
- npm.io page: https://npm.io/package/text2png

## Dependencies (2)

- [canvas](https://npm.io/package/canvas.md) ^2.6.0
- [commander](https://npm.io/package/commander.md) ^3.0.1

## Alternatives

- [ext-list](https://npm.io/package/ext-list.md) — 6.3M weekly downloads
- [@lexical/selection](https://npm.io/package/@lexical/selection.md) — 3.8M weekly downloads
- [@lexical/text](https://npm.io/package/@lexical/text.md) — 3.6M weekly downloads
- [@lexical/clipboard](https://npm.io/package/@lexical/clipboard.md) — 3.0M weekly downloads
- [@tiptap/extension-mention](https://npm.io/package/@tiptap/extension-mention.md) — 3.0M weekly downloads

## Recent versions

- 2.3.0 (latest) — 2019-10-19
- 2.1.0 (next) — 2018-10-19
- 2.2.0 — 2019-09-11
- 2.0.0-alpha.8 — 2018-04-17
- 1.1.1 — 2018-04-17
- 2.0.0-alpha.7 — 2018-04-17
- 2.0.0-alpha.6 — 2018-04-17
- 2.0.0-alpha.5 — 2018-04-10
- 2.0.0-alpha.4 — 2018-04-10
- 2.0.0-alpha.3 — 2018-04-10
- 2.0.0-alpha.2 — 2018-04-10
- 2.0.0-alpha.1 — 2018-02-19
- 1.1.0 — 2018-02-19
- 1.0.1 — 2016-04-12
- 1.0.0 — 2016-04-12

## README

[![NPM](https://nodei.co/npm/text2png.png)](https://nodei.co/npm/text2png/)
[![npm version](https://badge.fury.io/js/text2png.svg)](https://badge.fury.io/js/text2png)
[![Build Status](https://travis-ci.org/tkrkt/text2png.svg?branch=master)](https://travis-ci.org/tkrkt/text2png)

# text2png: text-to-png generator for Node.js

```js
text2png('Create png image\nfrom multi-line text!');
```

![text2png](./img/text2png.png)

## Quick start

text2png depends on [node-canvas](https://github.com/Automattic/node-canvas).
See [node-canvas wiki](https://github.com/Automattic/node-canvas/wiki) on installing node-canvas.

```
$ npm install text2png
```

```js
var fs = require('fs');
var text2png = require('text2png');
fs.writeFileSync('out.png', text2png('Hello!', {color: 'blue'}));
```

## Option

``text2png(text, option)``

|param|default|
|---|---|
|text|(required)|
|option.font|'30px sans-serif'|
|option.textAlign|'left'|
|option.color (or option.textColor)|'black'|
|option.backgroundColor (or option.bgColor)|'transparent'|
|option.lineSpacing|0|
|option.strokeWidth|0|
|option.strokeColor|'white'|
|option.padding|0|
|option.padding(Left\|Top\|Right\|Bottom)|0|
|option.borderWidth|0|
|option.border(Left\|Top\|Right\|Bottom)Width|0|
|option.borderColor|'black'|
|option.localFontPath||
|option.localFontName||
|option.output|'buffer'|

``option.color = '#000' | 'rgb(0, 0, 0)' | 'black' | ...``

``option.output = 'buffer' | 'stream' | 'dataURL' | 'canvas'``

``option.strokeWidth = 1 | 2 | ... `` A padding may have to be set to avoid cutoff of stroke

``'canvas'`` returns [node-canvas](https://github.com/Automattic/node-canvas) object.

If you want to use any custom fonts without installing, use `localFontPath` and `localFontName` property.

```js
text2png('with custom fonts', {
  font: '50px Lobster',
  localFontPath: 'fonts/Lobstar-Regular.ttf',
  localFontName: 'Lobster'
});
```

## Command line interface

```
$ npm install -g text2png
$ text2png --help
$ text2png -t "Hello!" -o "output.png"
```

## Example

```js
text2png('Example\nText', {
  font: '80px Futura',
  color: 'teal',
  backgroundColor: 'linen',
  lineSpacing: 10,
  padding: 20
});
```

![ExampleText](./img/exampleText.png)

Enjoy!

---
_Source: https://npm.io/package/text2png · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
