You Cant Upload Png With Textual Chunks
png-itxt
Windows | Mac/Linux |
---|---|
Tool for calculation and reading textual data in PNG images using streams. All three textual chunks (iTXt
, zTXt
and tEXt
) can be both read and written by the tool. Chunks tin be filtered by chunk blazon and keyword equally required. Compressing and decompressing of data, where advisable, is handled transparently to the user so you only ever see the uncompressed values.
Three different methods are provided for using the tool:
- command line
- client side browser (cheers to browserify)
- node library (via crave)
Install with
npm install png-itxt
Using in Node
To apply the tool in your node programs you must first require the module. If installed with npm and so you could write the following.
var pngitxt =
Constants
The module exports constants for the types of the textual chunks. These tin can be accessed as follows.
pngitxt iTXt
pngitxt zTXt
pngitxt tEXt
Data Format
Chunk data should be provided and will exist returned every bit an object equally shown below. Note that this is the total declaration for a iTXt
chunk as will be produced by the program. However not all fields are required when passing data to the programme. Additionally some of these fields are not relevant to zTXt
and tEXt
chunks.
type : ' iTXt '
keyword : ' keyword '
value : ' value '
language : ' '
translated : ' '
compressed : false
compression_type : 0
See the table below for details of which fields are relevent to each chunk and what their default values are.
Field Name | Chunks | Default |
---|---|---|
blazon | ALL | iTXt |
keyword | ALL | None - must be specified for set |
value | ALL | None - must exist specified for ready |
lanuage | iTXt | empty string |
translated | iTXt | empty cord |
compressed | iTXt, zTXt | false apart from zTXt chunks |
compression_type | iTXt, zTXt | 0 (only valid value) |
prepare - Writing iTXt data
The set
part can be used to write new textual chunks to a paradigm or replace existing ones. The following example shows how a new iTXt chunk can be added with the keyword pizza and the value delicious. While only these 2 options are specified hither whatsoever of the other fields identified before tin be specified. If compressed is prepare to true and so the value will exist compressed before it is written to the image.
fs
The set function will overwrite all the chunks of the same type and the keyword. In the previous example is in that location were already iTXt chunks with the keyword pizza (the spec allows for more than one chunk with the same keyword) and then the values stored in those chunks would exist lost.
It is also possible to have different types of textual chunk with the same keyword. An option is provided to allow you to supplant all textual chunks with the same keyword regardless of their type. To exercise this specify the value true
as the second parameter to the function.
fs
In this case if there were already any iTXt, zTXT or tEXt chunks with the keyword pizza and then they would both exist replaced by a unmarried iTXt chunk with the new value.
Using gear up to Remove Chunks
In the special example where you lot pass zip
as the value to be stored then all chunks that would usually have been replaced will only be removed. For example the following example would result in all the textual chunks with the keyword pizza beingness removed from the image.
fs
Exceptions
An exception will be thrown if y'all pass in an unknown chunk type.
fs
get - Reading iTXt data
Retrieval of data is accomplished using the get role and callbacks. The callback will be invoked each time a matching chunk is found. It cannot be assumed that callback volition only be called in one case for a particular keyword. You are guaranteed that your callback volition exist chosen at least once fifty-fifty if no matching chunks are found - in that case a zip is provided instead of data. By default the go function will return any textual chunks that match the criteria provided. If you but want 1 blazon of chunk (east.g iTXt) and then meet the section of filters.
Callback Signature
The callback to the get role is given 2 parameters. The kickoff is used to indicate whether or not an error was encountered. The second returns the information found in the format outlined above. In the example of an error the information provided may not be null. For example if the error was caused when trying to inflate a compressed value then all the other data nerveless about the clamper will be returned with the mistake.
{
if ! err && data
panel
}
Finding a specific keyword
To find the text associated with a specific keyword you lot must call get and provide both the keyword and a callback. Passing null
as the keyword volition cause all textual chunks to be passed to the callback. If the keyword is not constitute the callback will exist called with null
for both parameters. Note equally mentioned previously this example will render whatever textual clamper that has the specified keyword. If you but want a specific type of clamper and then come across the section on filters beneath.
fs
Using Regular Expressions
Instead of providing a keyword you can provide a regular expression and all chunks whose keywords match the regular expression volition be passed to the callback function. If no chunks are found then the callback volition be called once with null
for both parameters.
fs
Finding all textual chunks
To detect all chunks simply provide a callback that takes two parameters. If no textual chunks are found the callback will be called once with goose egg
for both parameters. Otherwise it volition be called for each block.
fs
Filtering by Chunk Blazon
To filter the chunks by type you can provide an array of acceptable clamper types. Even so for yous convience three wrapper functions are provided if y'all are you are just looking for chunks of a particular type. These functions are shown beneath and, apart from the filters assortment, they accept the verbal same parameters as the normal get office.
{
}
fs
To specify a specific combination of chunk types use an array every bit shown in the following example where the information is filtered so that you merely get tEXt and iTXt chunks with the keyword pizza.
fs
Please notation that even if yous are only looking for one type of chunk the value must be passed as an array or an exception volition be thrown. You can specify whatever combination of chunk types that yous want just be aware that specifying all 3, as shown below, is the equivalent of having no filter.
fs
If no keyword is specified so the filter assortment can exist provided as the first parameter to the function.
fs
Exceptions
In all just 2 cases errors are indicated past passing them to the callback function. Withal if no callback function is provided or the filter arguement is wrong (i.e. information technology is not an array or doesn't contain any valid clamper types) and then exceptions will be thrown to signal this.
fs
Browser Library
As a test a browser libarary, produced using browserify in standalone mode, is available in the dist folder. Both a normal and minified version is provided. To include it on your webpage simple copy the bundled js file to the appropriate location and add the following. All exports from the library are then bachelor on the pngitxt object.
The library exposes the same constats every bit for node and tin be accessed in the same style. The library likewise exposes the same go and set functions merely there are some differences in how they are called. The signature for the become function is shown below. All the parameters are the same apart from the start one which should provide the binary data of the image to bank check. Such a cord can be obtained in diverse fashion including using the FileReader.readAsBinaryString method.
pngitxt
As before a number of helper functions are besides provided for those that want to search for only i blazon of text chunk. An example of how to call these methods in the browser are shown below.
var input = undefined
{
}
pngitxt
pngitxt
pngitxt
The ready part has a like input parameter and a data parameter as before. The last parameter is a callback that gives a binary string containing the altered image data. If, for case, you lot wanted to add an iTXt cake to a picture and then display the picture on a folio you tin can convert the data to a base64 encoding to brandish it on the page as follows.
pngitxt
A simple, crude and prepare proof of concept of this functionality is available as a webpage at dist/case.html. This page will allow you to elevate and drop images to either inspect their data or add boosted data.
Control Line Tool
The command line tool, called png-itxt
is provided in the bin binder and will exist automatically linked from the node_modules/.bin folder if installed with npm. The two commands information technology supports are as follows.
-
png-itxt get
-
png-itxt set
png-itxt become
This command allows you to seach an paradigm for textual chunks of any type and will output the result in JSON format. For example the following command will search the input.png file for a iTXT or zTXt chunk that has the keyword pizza and then output the results to standard output.
png-itxt become -m pizza -f iTXt,zTXt input.png
A consummate list of the options for the get command are shown below.
Usage: png-itxt-get [options] <file.png> Tool for getting textual information from PNG images Options: -h, --help output usage data -V, --version output the version number -k, --keyword <keyword> keyword to serach for -r, --regexp <expression> regular expression to search by -i, --ignorecase makes the search example insensitive -s, --stdin reads the paradigm data from standard input -f, --filter <chunktypes> comma seperated list of clamper types to render -o, --output <file> write results to a file
png-itxt set
This command allows you to add iTXt chunk to an prototype. For instance the following command will add a clamper with keyword pizza and the value delicious to an epitome from the file input.png and and then salve it to output.png. The command can likewise be used to read data from stdin and output the issue to stdout and so that you tin can pipe the information betwixt commands. Notation that this tool will only add iTXt chunks.
png-itxt prepare -chiliad pizza -d delicious -o output.png input.png
A full list of all the avilable options available for apply with the set command are shown below.
Usage: png-itxt-gear up [options] <fileIn.png> Tool for setting textual information into a PNG images. If no output method is specified output volition be put into {fileIn}_out.png Options: -h, --help output usage information -V, --version output the version number -k, --keyword <keyword> keyword to set up the value for -d, --data <chunkdata> data to store with the keyword -f, --file <datafile> text file to read the value from -v, --valuein read data to store from standard input -c, --compress compress the value stored in the clamper -due south, --stdin read png data from standard input -p, --pipe redirect output to stdout for processing -o, --output <file> file to output PNG data to
Source: https://www.npmjs.com/package/png-itxt
0 Response to "You Cant Upload Png With Textual Chunks"
Post a Comment