Gathering detailed insights and metrics for @uttori/image-png
Gathering detailed insights and metrics for @uttori/image-png
npm install @uttori/image-png
Typescript
Module System
Min. Node Version
Node Version
NPM Version
JavaScript (97.09%)
Handlebars (2.24%)
HTML (0.67%)
Love this project? Help keep it running — sponsor us today! 🚀
Total Downloads
1,669
Last Day
1
Last Week
10
Last Month
45
Last Year
481
1 Stars
22 Commits
1 Watching
3 Branches
1 Contributors
Minified
Minified + Gzipped
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
Cumulative downloads
Total Downloads
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
2
33
1
A PNG Decoder and meta data reading utility.
1npm install --save @uttori/image-png
1{ 2}
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]
DataBuffer
PNG Decoder
function
DataBuffer
PNG Decoder
Kind: global class
Extends: DataBuffer
See
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 |
DataBuffer
number
number
number
number
number
number
number
number
boolean
Array.<number>
| Uint8Array
Uint8Array
Uint8Array
object
Array.<Uint8Array>
Array
| Uint8Array
Array
string
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]
number
Pixel Width
Kind: instance property of ImagePNG
number
Pixel Height
Kind: instance property of ImagePNG
number
Image Bit Depth, one of: 1, 2, 4, 8, 16
Kind: instance property of ImagePNG
number
Defines pixel structure, one of: 0, 2, 3, 4, 6
Kind: instance property of ImagePNG
number
Type of compression, always 0
Kind: instance property of ImagePNG
number
Type of filtering, always 0
Kind: instance property of ImagePNG
number
Type of interlacing, one of: 0, 1
Kind: instance property of ImagePNG
number
Number of bytes for each pixel
Kind: instance property of ImagePNG
boolean
True when the image has an alpha transparency layer
Kind: instance property of ImagePNG
Array.<number>
| Uint8Array
Raw Color data
Kind: instance property of ImagePNG
Uint8Array
Raw Image Pixel data
Kind: instance property of ImagePNG
Uint8Array
Raw Transparency data
Kind: instance property of ImagePNG
object
physical - Object containing physical dimension information
Kind: instance property of ImagePNG
number
Physical Dimension Width
Kind: static property of physical
number
Physical Dimension Height
Kind: static property of physical
number
Physical Dimension Units, with 0 being unknown and 1 being Meters
Kind: static property of physical
Array.<Uint8Array>
Image Data pieces
Kind: instance property of ImagePNG
Array
| Uint8Array
PNG Signature from the data
Kind: instance property of ImagePNG
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 |
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, 6Param | Type | Description |
---|---|---|
colorType | number | The colorType to set, one of: 0, 2, 3, 4, 6 |
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 0Param | Type | Description |
---|---|---|
compressionMethod | number | The compressionMethod to set, always 0 |
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 0Param | Type | Description |
---|---|---|
filterMethod | number | The filterMethod to set, always 0 |
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 1Param | Type | Description |
---|---|---|
interlaceMethod | number | The filterMethod to set, always 0 or 1 |
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 depthParam | Type | Description |
---|---|---|
palette | Array.<number> | Uint8Array | The palette to set |
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 typesParam | Type | Description |
---|---|---|
x | number | The hoizontal offset to read. |
y | number | The vertical offset to read. |
Parse the PNG file, decoding the supported chunks.
Kind: instance method of ImagePNG
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 headerSee: PNG Signature
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 0See: Chunk Layout
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 |
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 |
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 |
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 |
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 |
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. |
Uncompress IDAT chunks.
Kind: instance method of ImagePNG
Throws:
Error
No IDAT chunks to decodeError
Deinterlacing ErrorError
Inflating ErrorError
Adam7 interlaced format is unsupportedDeinterlace with no interlacing.
Kind: instance method of ImagePNG
See: PNG Filters
Param | Type | Description |
---|---|---|
data | Buffer | Data to deinterlace. |
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 |
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
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
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. |
function
Kind: global function
To run the test suite, first install the dependencies, then run npm test
:
1npm install 2npm test 3DEBUG=Uttori* npm test
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
Reason
license file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
30 existing vulnerabilities detected
Details
Score
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