GithubHelp home page GithubHelp logo

hughsk / png-chunk-text Goto Github PK

View Code? Open in Web Editor NEW
33.0 4.0 3.0 149 KB

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

License: MIT License

JavaScript 100.00%

png-chunk-text's Introduction

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.

png-chunk-text's People

Contributors

hughsk avatar

Stargazers

GAI Group avatar mizt avatar Heico avatar CENTR avatar Vaidas Bagdonas avatar Guilherme Pacheco avatar  avatar Işık avatar kk avatar Jamie Leviner avatar nodojo avatar Adam Bouhenguel avatar varHarrie avatar Lynn avatar Sam Collard avatar Mateusz Bochyński avatar Jack B. Du avatar Matthew avatar syzer avatar  avatar  avatar Antonín Jareš avatar  avatar Yuki Shichiku avatar  avatar Thibaut Séguy avatar Kostas Minaidis avatar Michael Anthony avatar Athan avatar Mark Moissette avatar Pelle Wessman avatar Mikola Lysenko avatar Ivan Malopinsky avatar

Watchers

 avatar James Cloos avatar Michael Anthony avatar  avatar

png-chunk-text's Issues

Remove previous

Would it be possible to remove earlier chunks without rewriting the entire file?

png-chunk-text usable from chrome extension?

Hi!

png-chunk-text seems an interesting project - i didn't know that there are node modules that dive into the depths of the png format :-)

one question: is png-chunk-text also usable from a google chrome extension? I like to integrate it into a extension that captures a screenshot of the current chrome tab. I like to use png-chunk-text to annotate the screenshot png (e.g. store the exact version of the webapp being captured in the screenshot in an iText chunk), much like EXIF is used to annotate the shooting settings of a digital photo.

Best,

Franz

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.