# png-chunk-text

> Create or parse a PNG tEXt chunk for storing uncompressed text data in PNG images

Latest version **1.0.0** (published 2015-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install png-chunk-text
pnpm add png-chunk-text
yarn add png-chunk-text
bun add png-chunk-text
```

## Health

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

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2015-10-04 |
| First published | 2015-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/png-chunk-text) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 35 |
| Author | Hugh Kennedy |
| Maintainers | hughsk |
| Keywords | encode,, decode,, tEXt,, chunk,, png,, image,, metadata,, hiding,, format |

## Links

- npm: https://www.npmjs.com/package/png-chunk-text
- Repository: https://github.com/hughsk/png-chunk-text
- Issues: https://github.com/hughsk/png-chunk-text/issues
- npm.io page: https://npm.io/package/png-chunk-text

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2015-10-04

## README

# png-chunk-text

[![stable](http://badges.github.io/stability-badges/dist/stable.svg)](http://github.com/badges/stability-badges)

Create or parse a PNG tEXt chunk for storing uncompressed text data in PNG images.

Can be used in combination with [png-chunks-extract](https://github.com/hughsk/png-chunks-extract) and [png-chunks-encode](https://github.com/hughsk/png-chunks-encode) for adding and reading custom metadata in PNG images.

Works in Node, or in the browser using [browserify](http://browserify.org/).

## Usage

[![NPM](https://nodei.co/npm/png-chunk-text.png)](https://www.npmjs.com/package/png-chunk-text)

### `chunk = text.encode(key, value)`

Returns a chunk object containing the metadata for a given `key` and `value`:

``` javascript
{
  name: 'tEXt',
  data: Uint8Array([...])
}
```

``` javascript
const extract = require('png-chunks-extract')
const encode = require('png-chunks-encode')
const text = require('png-chunk-text')
const path = require('path')
const fs = require('fs')

const buffer = fs.readFileSync(path.join(__dirname, 'test.png'))
const chunks = extract(buffer)

// Add new chunks before the IEND chunk
chunks.splice(-1, 0, text.encode('hello', 'world'))
chunks.splice(-1, 0, text.encode('lorem', 'ipsum'))

fs.writeFileSync(
  path.join(__dirname, 'test-out.png'),
  new Buffer(encode(chunks))
)
```

### `data = text.decode(chunk)`

Reads a `Uint8Array` or Node.js `Buffer` instance containing a `tEXt` PNG chunk's data and returns its keyword/text:

``` javascript
{
  keyword: 'hello',
  text: 'world'
}
```

``` javascript
const extract = require('png-chunks-extract')
const text = require('png-chunk-text')
const path = require('path')
const fs = require('fs')

const buffer = fs.readFileSync(path.join(__dirname, 'test-out.png'))
const chunks = extract(buffer)

const textChunks = chunks.filter(function (chunk) {
  return chunk.name === 'tEXt'
}).map(function (chunk) {
  return text.decode(chunk.data)
})

console.log(textChunks[0].keyword) // 'hello'
console.log(textChunks[0].text)    // 'world'
console.log(textChunks[1].keyword) // 'lorem'
console.log(textChunks[1].text)    // 'ipsum'
```

## See Also

* [png-chunks-extract](https://github.com/hughsk/png-chunks-extract)
* [png-chunks-encode](https://github.com/hughsk/png-chunks-encode)

## License

MIT, see [LICENSE.md](http://github.com/hughsk/png-chunk-text/blob/master/LICENSE.md) for details.

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