Socket
Socket
Sign inDemoInstall

png-chunk-text

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    png-chunk-text

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


Version published
Weekly downloads
8.3K
decreased by-16.6%
Maintainers
1
Install size
65.4 kB
Created
Weekly downloads
 

Readme

Source

png-chunk-text

stable

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

Can be used in combination with png-chunks-extract and png-chunks-encode for adding and reading custom metadata in PNG images.

Works in Node, or in the browser using browserify.

Usage

NPM

chunk = text.encode(key, value)

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

{
  name: 'tEXt',
  data: Uint8Array([...])
}
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:

{
  keyword: 'hello',
  text: 'world'
}
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

License

MIT, see LICENSE.md for details.

Keywords

FAQs

Last updated on 04 Oct 2015

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