Installations
npm install @uttori/image-png
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM, UMD
Min. Node Version
>= 14
Node Version
16.13.1
NPM Version
8.1.2
Releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (97.09%)
Handlebars (2.24%)
HTML (0.67%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
uttori
Download Statistics
Total Downloads
1,669
Last Day
1
Last Week
10
Last Month
45
Last Year
481
GitHub Statistics
1 Stars
22 Commits
1 Watching
3 Branches
1 Contributors
Bundle Size
34.78 kB
Minified
11.17 kB
Minified + Gzipped
Package Meta Information
Latest Version
1.3.0
Package Id
@uttori/image-png@1.3.0
Unpacked Size
430.80 kB
Size
92.05 kB
File Count
9
NPM Version
8.1.2
Node Version
16.13.1
Total Downloads
Cumulative downloads
Total Downloads
1,669
Last day
-66.7%
1
Compared to previous day
Last week
0%
10
Compared to previous week
Last month
4.7%
45
Compared to previous month
Last year
94%
481
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
2
Dev Dependencies
33
Optional Dependencies
1
Uttori ImagePNG
A PNG Decoder and meta data reading utility.
Install
1npm install --save @uttori/image-png
Config
1{ 2}
Example
1const image_data = await FileUtility.readFile('./test/assets/PngSuite', 'oi1n0g16', 'png', null); 2const image = ImagePNG.fromFile(image_data); 3image.decodePixels(); 4const length = image.pixels.length; 5➜ 6144 6const pixel = image.getPixel(0, 0); 7➜ [255, 255, 255, 255]
API Reference
Classes
- ImagePNG ⇐
DataBuffer
PNG Decoder
Functions
- debug() :
function
ImagePNG ⇐ DataBuffer
PNG Decoder
Kind: global class
Extends: DataBuffer
See
- Chunk Specifications
- The Art of PNG Glitch
- PngSuite, test-suite for PNG
- Chunk Specifications (LibPNG)
- Chunk Specifications (W3C)
- PNGs containing a chunk with length 0xffffffff
- PNG files can be animated via network latency
- TweakPNG
Properties
Name | Type | Description |
---|---|---|
width | number | Pixel Width |
height | number | Pixel Height |
bitDepth | number | Image Bit Depth, one of: 1, 2, 4, 8, 16 |
colorType | number | = Defines pixel structure, one of: 0, 2, 3, 4, 6 |
compressionMethod | number | Type of compression, always 0 |
filterMethod | number | Type of filtering, always 0 |
interlaceMethod | number | Type of interlacing, one of: 0, 1 |
colors | number | Number of bytes for each pixel |
alpha | boolean | True when the image has an alpha transparency layer |
palette | Array.<number> | Uint8Array | Raw Color data |
pixels | Uint8Array | Raw Image Pixel data |
transparency | Uint8Array | Raw Transparency data |
physical | object | Object containing physical dimension information |
physical.width | number | Physical Dimension Width |
physical.height | number | Physical Dimension Height |
physical.unit | number | Physical Dimension Units, with 0 being unknown and 1 being Meters |
dataChunks | Array.<Uint8Array> | Image Data pieces |
header | Uint8Array | PNG Signature from the data |
- ImagePNG ⇐
DataBuffer
- new ImagePNG(input)
- instance
- .width :
number
- .height :
number
- .bitDepth :
number
- .colorType :
number
- .compressionMethod :
number
- .filterMethod :
number
- .interlaceMethod :
number
- .colors :
number
- .alpha :
boolean
- .palette :
Array.<number>
|Uint8Array
- .pixels :
Uint8Array
- .transparency :
Uint8Array
- .physical :
object
- .dataChunks :
Array.<Uint8Array>
- .header :
Array
|Uint8Array
- .setBitDepth(bitDepth)
- .setColorType(colorType)
- .setCompressionMethod(compressionMethod)
- .setFilterMethod(filterMethod)
- .setInterlaceMethod(interlaceMethod)
- .setPalette(palette)
- .getPixel(x, y) ⇒
Array
- .parse()
- .decodeHeader()
- .decodeChunk() ⇒
string
- .decodeIHDR(chunk)
- .decodePLTE(chunk)
- .decodeIDAT(chunk)
- .decodeTRNS(chunk)
- .decodePHYS(chunk)
- .decodeIEND(_chunk)
- .decodePixels()
- .interlaceNone(data)
- .unFilterNone(scanline, bpp, offset, length)
- .unFilterSub(scanline, bpp, offset, length)
- .width :
- static
new ImagePNG(input)
Creates a new ImagePNG.
Param | Type | Description |
---|---|---|
input | Array | ArrayBuffer | Buffer | DataBuffer | Int8Array | Int16Array | Int32Array | number | string | Uint8Array | Uint16Array | Uint32Array | The data to process. |
Example (new ImagePNG(list, options))
1const image_data = await FileUtility.readFile('./test/assets/PngSuite', 'oi1n0g16', 'png', null); 2const image = ImagePNG.fromFile(image_data); 3image.decodePixels(); 4const length = image.pixels.length; 5 ➜ 6144 6const pixel = image.getPixel(0, 0); 7 ➜ [255, 255, 255, 255]
imagePNG.width : number
Pixel Width
Kind: instance property of ImagePNG
imagePNG.height : number
Pixel Height
Kind: instance property of ImagePNG
imagePNG.bitDepth : number
Image Bit Depth, one of: 1, 2, 4, 8, 16
Kind: instance property of ImagePNG
imagePNG.colorType : number
Defines pixel structure, one of: 0, 2, 3, 4, 6
Kind: instance property of ImagePNG
imagePNG.compressionMethod : number
Type of compression, always 0
Kind: instance property of ImagePNG
imagePNG.filterMethod : number
Type of filtering, always 0
Kind: instance property of ImagePNG
imagePNG.interlaceMethod : number
Type of interlacing, one of: 0, 1
Kind: instance property of ImagePNG
imagePNG.colors : number
Number of bytes for each pixel
Kind: instance property of ImagePNG
imagePNG.alpha : boolean
True when the image has an alpha transparency layer
Kind: instance property of ImagePNG
imagePNG.palette : Array.<number>
| Uint8Array
Raw Color data
Kind: instance property of ImagePNG
imagePNG.pixels : Uint8Array
Raw Image Pixel data
Kind: instance property of ImagePNG
imagePNG.transparency : Uint8Array
Raw Transparency data
Kind: instance property of ImagePNG
imagePNG.physical : object
physical - Object containing physical dimension information
Kind: instance property of ImagePNG
physical.width : number
Physical Dimension Width
Kind: static property of physical
physical.height : number
Physical Dimension Height
Kind: static property of physical
physical.unit : number
Physical Dimension Units, with 0 being unknown and 1 being Meters
Kind: static property of physical
imagePNG.dataChunks : Array.<Uint8Array>
Image Data pieces
Kind: instance property of ImagePNG
imagePNG.header : Array
| Uint8Array
PNG Signature from the data
Kind: instance property of ImagePNG
imagePNG.setBitDepth(bitDepth)
Sets the bitDepth on the ImagePNG instance.
Kind: instance method of ImagePNG
Param | Type | Description |
---|---|---|
bitDepth | number | The bitDepth to set, one of: 1, 2, 4, 8, 16 |
imagePNG.setColorType(colorType)
Sets the colorType on the ImagePNG instance. Both color and alpha properties are inferred from the colorType.
Color Type | Allowed Bit Depths | Interpretation |
---|---|---|
0 | 1, 2, 4, 8, 16 | Each pixel is a grayscale sample. |
2 | 8, 16 | Each pixel is an R, G, B triple. |
3 | 1, 2, 4, 8 | Each pixel is a palette index; a PLTE chunk must appear. |
4 | 8, 16 | Each pixel is a grayscale sample, followed by an alpha sample. |
6 | 8, 16 | Each pixel is an R, G, B triple, followed by an alpha sample. |
Kind: instance method of ImagePNG
Throws:
Error
Invalid Color Type, anything other than 0, 2, 3, 4, 6
Param | Type | Description |
---|---|---|
colorType | number | The colorType to set, one of: 0, 2, 3, 4, 6 |
imagePNG.setCompressionMethod(compressionMethod)
Sets the compressionMethod on the ImagePNG instance. The compressionMethod should always be 0.
Kind: instance method of ImagePNG
Throws:
Error
Unsupported Compression Method, anything other than 0
Param | Type | Description |
---|---|---|
compressionMethod | number | The compressionMethod to set, always 0 |
imagePNG.setFilterMethod(filterMethod)
Sets the filterMethod on the ImagePNG instance. The filterMethod should always be 0.
Kind: instance method of ImagePNG
Throws:
Error
Unsupported Filter Method, anything other than 0
Param | Type | Description |
---|---|---|
filterMethod | number | The filterMethod to set, always 0 |
imagePNG.setInterlaceMethod(interlaceMethod)
Sets the interlaceMethod on the ImagePNG instance. The interlaceMethod should always be 0 or 1.
Kind: instance method of ImagePNG
Throws:
Error
Unsupported Interlace Method, anything other than 0 or 1
Param | Type | Description |
---|---|---|
interlaceMethod | number | The filterMethod to set, always 0 or 1 |
imagePNG.setPalette(palette)
Sets the palette on the ImagePNG instance.
Kind: instance method of ImagePNG
Throws:
Error
No colors in the paletteError
Too many colors for the current bit depth
Param | Type | Description |
---|---|---|
palette | Array.<number> | Uint8Array | The palette to set |
imagePNG.getPixel(x, y) ⇒ Array
Get the pixel color at a specified x, y location.
Kind: instance method of ImagePNG
Returns: Array
- the color as [red, green, blue, alpha]
Throws:
Error
x is out of bound for the imageError
y is out of bound for the imageError
Unknown color types
Param | Type | Description |
---|---|---|
x | number | The hoizontal offset to read. |
y | number | The vertical offset to read. |
imagePNG.parse()
Parse the PNG file, decoding the supported chunks.
Kind: instance method of ImagePNG
imagePNG.decodeHeader()
Decodes and validates PNG Header. Signature (Decimal): [137, 80, 78, 71, 13, 10, 26, 10] Signature (Hexadecimal): [89, 50, 4E, 47, 0D, 0A, 1A, 0A] Signature (ASCII): [\211, P, N, G, \r, \n, \032, \n]
Kind: instance method of ImagePNG
Throws:
Error
Missing or invalid PNG header
See: PNG Signature
imagePNG.decodeChunk() ⇒ string
Decodes the chunk type, and attempts to parse that chunk if supported. Supported Chunk Types: IHDR, PLTE, IDAT, IEND, tRNS, pHYs
Chunk Structure: Length: 4 bytes Type: 4 bytes (IHDR, PLTE, IDAT, IEND, etc.) Chunk: {length} bytes CRC: 4 bytes
Kind: instance method of ImagePNG
Returns: string
- Chunk Type
Throws:
Error
Invalid Chunk Length when less than 0
See: Chunk Layout
imagePNG.decodeIHDR(chunk)
Decode the IHDR (Image header) chunk. Should be the first chunk in the data stream.
Width: 4 bytes Height: 4 bytes Bit Depth: 1 byte Colour Type: 1 byte Compression Method: 1 byte Filter Method: 1 byte Interlace Method: 1 byte
Kind: instance method of ImagePNG
See
Param | Type | Description |
---|---|---|
chunk | Uint8Array | Data Blob |
imagePNG.decodePLTE(chunk)
Decode the PLTE (Palette) chunk. The PLTE chunk contains from 1 to 256 palette entries, each a three-byte series of the form. The number of entries is determined from the chunk length. A chunk length not divisible by 3 is an error.
Kind: instance method of ImagePNG
See: Palette
Param | Type | Description |
---|---|---|
chunk | Uint8Array | Data Blob |
imagePNG.decodeIDAT(chunk)
Decode the IDAT (Image Data) chunk. The IDAT chunk contains the actual image data which is the output stream of the compression algorithm.
Kind: instance method of ImagePNG
See: Image Data
Param | Type | Description |
---|---|---|
chunk | Uint8Array | Data Blob |
imagePNG.decodeTRNS(chunk)
Decode the tRNS (Transparency) chunk. The tRNS chunk specifies that the image uses simple transparency: either alpha values associated with palette entries (for indexed-color images) or a single transparent color (for grayscale and truecolor images). Although simple transparency is not as elegant as the full alpha channel, it requires less storage space and is sufficient for many common cases.
Kind: instance method of ImagePNG
See: Transparency
Param | Type | Description |
---|---|---|
chunk | Uint8Array | Data Blob |
imagePNG.decodePHYS(chunk)
Decode the pHYs (Pixel Dimensions) chunk. The pHYs chunk specifies the intended pixel size or aspect ratio for display of the image. When the unit specifier is 0, the pHYs chunk defines pixel aspect ratio only; the actual size of the pixels remains unspecified. If the pHYs chunk is not present, pixels are assumed to be square, and the physical size of each pixel is unspecified.
Structure: Pixels per unit, X axis: 4 bytes (unsigned integer) Pixels per unit, Y axis: 4 bytes (unsigned integer) Unit specifier: 1 byte 0: unit is unknown 1: unit is the meter
Kind: instance method of ImagePNG
See: Pixel Dimensions
Param | Type | Description |
---|---|---|
chunk | Uint8Array | Data Blob |
imagePNG.decodeIEND(_chunk)
Decode the IEND (Image trailer) chunk. The IEND chunk marks the end of the PNG DataBuffer. The chunk's data field is empty.
Kind: instance method of ImagePNG
See: Image Trailer
Param | Type | Description |
---|---|---|
_chunk | Uint8Array | Unused. |
imagePNG.decodePixels()
Uncompress IDAT chunks.
Kind: instance method of ImagePNG
Throws:
Error
No IDAT chunks to decodeError
Deinterlacing ErrorError
Inflating ErrorError
Adam7 interlaced format is unsupported
imagePNG.interlaceNone(data)
Deinterlace with no interlacing.
Kind: instance method of ImagePNG
See: PNG Filters
Param | Type | Description |
---|---|---|
data | Buffer | Data to deinterlace. |
imagePNG.unFilterNone(scanline, bpp, offset, length)
No filtering, direct copy.
Kind: instance method of ImagePNG
Param | Type | Description |
---|---|---|
scanline | Array | Uint8Array | Scanline to search for pixels in. |
bpp | number | Bytes Per Pixel |
offset | number | Offset |
length | number | Length |
imagePNG.unFilterSub(scanline, bpp, offset, length)
The Sub() filter transmits the difference between each byte and the value of the corresponding byte of the prior pixel. Sub(x) = Raw(x) + Raw(x - bpp)
Kind: instance method of ImagePNG
Param | Type | Description |
---|---|---|
scanline | Array | Uint8Array | Scanline to search for pixels in. |
bpp | number | Bytes Per Pixel |
offset | number | Offset |
length | number | Length |
ImagePNG.fromFile(data) ⇒ ImagePNG
Creates a new ImagePNG from file data.
Kind: static method of ImagePNG
Returns: ImagePNG
- the new ImagePNG instance for the provided file data
Param | Type | Description |
---|---|---|
data | Array | ArrayBuffer | Buffer | DataBuffer | Int8Array | Int16Array | Int32Array | number | string | Uint8Array | Uint16Array | Uint32Array | The data of the image to process. |
ImagePNG.fromBuffer(buffer) ⇒ ImagePNG
Creates a new ImagePNG from a DataBuffer.
Kind: static method of ImagePNG
Returns: ImagePNG
- the new ImagePNG instance for the provided DataBuffer
Param | Type | Description |
---|---|---|
buffer | DataBuffer | The DataBuffer of the image to process. |
debug() : function
Kind: global function
Tests
To run the test suite, first install the dependencies, then run npm test
:
1npm install 2npm test 3DEBUG=Uttori* npm test
Contributors
License
![Empty State](/_next/static/media/empty.e5fae2e5.png)
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
Found 0/20 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
license file not detected
Details
- Warn: project does not have a license file
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 3 are checked with a SAST tool
Reason
30 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
- Warn: Project is vulnerable to: GHSA-rc47-6667-2j5j
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-p6mc-m468-83gw
- Warn: Project is vulnerable to: GHSA-6vfc-qv3f-vr6c
- Warn: Project is vulnerable to: GHSA-5v2h-r2cx-5xgj
- Warn: Project is vulnerable to: GHSA-rrrm-qjm4-v8hf
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-r683-j2x4-v87g
- Warn: Project is vulnerable to: GHSA-3j8f-xvm3-ffx4
- Warn: Project is vulnerable to: GHSA-4p35-cfcx-8653
- Warn: Project is vulnerable to: GHSA-7f3x-x4pr-wqhj
- Warn: Project is vulnerable to: GHSA-jpp7-7chh-cf67
- Warn: Project is vulnerable to: GHSA-q6wq-5p59-983w
- Warn: Project is vulnerable to: GHSA-j9fq-vwqv-2fm2
- Warn: Project is vulnerable to: GHSA-pqw5-jmp5-px4v
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-mxhp-79qh-mcx6
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
Score
1.3
/10
Last Scanned on 2025-01-27
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More