Png Image Class for generation png images.
- Source:
- Version:
- 1.0
- Copyright:
- Copyright (c) 2017, Grigory Vasilyev
- License:
- Apache License, Version 2.0, http://www.apache.org/licenses/LICENSE-2.0
Members
(static) default
- Source:
Export PNG Image Class.
Methods
(static) PngImage(depth, colortype)
- Source:
Color depths: PNG image type Colour type Allowed bit depths Interpretation Greyscale 0 1, 2, 4, 8, 16 Each pixel is a greyscale sample Truecolor 2 8, 16 Each pixel is an R,G,B triple Indexed-color 3 1, 2, 4, 8 Each pixel is a palette index; a PLTE chunk shall appear. Greyscale with alpha 4 8, 16 Each pixel is a greyscale sample followed by an alpha sample. Truecolor with alpha 6 8, 16 Each pixel is an R,G,B triple followed by an alpha sample.
Parameters:
| Name | Type | Description |
|---|---|---|
depth |
number | color depth. |
colortype |
number | png color type. |
(static) PngImage#adler32(data) → {number}
- Source:
Adler 32 algorithm. Calculate hash for bytes.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
input bytes. |
Returns:
- adler32 hash.
- Type
- number
(static) PngImage#base64(data) → {Buffer}
- Source:
Generate base64 string from bytes.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
input bytes. |
Returns:
- base64 string.
- Type
- Buffer
(static) PngImage#byte2(data)
- Source:
Return 2 bytes value from input.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
input value. |
Returns:
Uint8Array - 2 bytes.
(static) PngImage#byte2lsb(data)
- Source:
Return 2 lsb(least significant bit) bytes value from input.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
input value. |
Returns:
Uint8Array - 2 lsb bytes.
(static) PngImage#byte4(data)
- Source:
Return 4 bytes value from input.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
input value. |
Returns:
Uint8Array - 4 bytes.
(static) PngImage#color(red, green, blue, alpha)
- Source:
All values must be from 0 to 255.
Parameters:
| Name | Type | Description |
|---|---|---|
red |
Number | red value in rgb palette. |
green |
Number | green value in rgb palette. |
blue |
Number | blue value in rgb palette. |
alpha |
Number | transparency value. |
Returns:
Uint8Array - color encoded as bytes.
(static) PngImage#crc32(data, crc)
- Source:
Calculate crc32(Cyclic redundancy check) checksum for bytes.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
input bytes. |
|
crc |
start crc value, default - 1. |
Returns:
byte4 - crc32 checksum.
(static) PngImage#fromBase64(data) → {Buffer}
- Source:
Generate bytes from base64 string.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
input base64 string. |
Returns:
- output bytes in Buffer.
- Type
- Buffer
(static) PngImage#fromHex(data) → {Buffer}
- Source:
Generate bytes from hex string.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
string | input hex string. |
Returns:
- output bytes in Buffer.
- Type
- Buffer
(static) PngImage#getBase64() → {Buffer}
- Source:
Return png image in base64 format.
Returns:
- base64 string - encoded image.
- Type
- Buffer
(static) PngImage#getFile(filename)
- Source:
Write image to file.
Parameters:
| Name | Type | Description |
|---|---|---|
filename |
image file name. |
(static) PngImage#hex(data) → {Buffer}
- Source:
Generate hex string from bytes.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
input bytes. |
Returns:
- hex string.
- Type
- Buffer
(static) PngImage#makeIDAT()
- Source:
Generate IDAT Chunk for image. Deflate image matrix.
(static) PngImage#makeImage()
- Source:
Make image before output. Glue all PNG Chunks with PNG Header.
(static) PngImage#parseColor(color)
- Source:
Parse color from string.
Parameters:
| Name | Type | Description |
|---|---|---|
color |
string | color as string. Support hex color like #454545, web safe hex like #333, rgb(255, 143, 15) - red, green, blue, rgba(255, 143, 15, 0.6) - red, green, blue, alpha(transparency). |
Returns:
Uint8Array - color for png image encoded as bytes.
(static) PngImage#rulerMatrix(height, color, pattern, thickness, scale)
- Source:
Filter Types: 0 None Filt(x) = Orig(x) Recon(x) = Filt(x) 1 Sub Filt(x) = Orig(x) - Orig(a) Recon(x) = Filt(x) + Recon(a) 2 Up Filt(x) = Orig(x) - Orig(b) Recon(x) = Filt(x) + Recon(b) 3 Average Filt(x) = Orig(x) - floor((Orig(a) + Orig(b)) / 2) Recon(x) = Filt(x) + floor((Recon(a) + Recon(b)) / 2) 4 Paeth Filt(x) = Orig(x) - PaethPredictor(Orig(a), Orig(b), Orig(c)) Recon(x) = Filt(x) + PaethPredictor(Recon(a), Recon(b), Recon(c)
Parameters:
| Name | Type | Description |
|---|---|---|
height |
number | image height. |
color |
string | ruler line color. Support hex color like #454545, web safe hex like #333, rgb(255, 143, 15) - red, green, blue, rgba(255, 143, 15, 0.6) - red, green, blue, alpha(transparency). |
pattern |
array | ruler line pattern array like [1, 0, 0, 0] - value = 1 - write color pixel, values = 0 write transparent pixel. |
thickness |
number | ruler line thickness in pixels. |
scale |
number | image scale ratio. |
(static) PngImage#setIHDR(height, width)
- Source:
IHDR Format: 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
Parameters:
| Name | Type | Description |
|---|---|---|
height |
number | image height. |
width |
number | image width. |