Options
All
  • Public
  • Public/Protected
  • All
Menu

node-libpng

Index

Type aliases

ColorAny

ColorGrayScale

ColorGrayScale: [number] & object

Represents a color of color type ColorType.GRAY_SCALE.

see

ColorType

ColorGrayScaleAlpha

ColorGrayScaleAlpha: [number, number] & object

Represents a color of color type ColorType.GRAY_SCALE_A.

see

ColorType

ColorNoAlpha

ColorPalette

ColorPalette: [number] & object

Represents a color of color type ColorType.PALETTE.

see

ColorType

ColorRGB

ColorRGB: [number, number, number] & object

Represents a color of color type ColorType.RGB.

see

ColorType

ColorRGBA

ColorRGBA: [number, number, number, number] & object

Represents a color of color type ColorType.RGBA.

see

ColorType

Palette

Palette: Map<number, ColorRGB>

A palette used by libpng to lookup colors in.

ReadPngFileCallback

ReadPngFileCallback: function

Type declaration

    • (error: Error, pngImage?: PngImage): void
    • Parameters

      • error: Error
      • Optional pngImage: PngImage

      Returns void

Rect

Rect: [number, number, number, number] & object

WritePngFileCallback

WritePngFileCallback: function

Type declaration

    • (error: Error): void
    • Parameters

      • error: Error

      Returns void

XY

XY: [number, number] & object

Variables

__native_PngImage

__native_PngImage: any

__native_copy

__native_copy: any

__native_encode

__native_encode: any

__native_fill

__native_fill: any

__native_isPng

__native_isPng: any

__native_resize

__native_resize: any

Functions

colorGrayScale

  • Create a new color of type ColorGrayScale.

    Parameters

    • gray: number

      The value for the gray part of the color.

    Returns ColorGrayScale

    The color in gray scale representation.

colorGrayScaleAlpha

  • Create a new color of type gray scale with alpha channel.

    Parameters

    • gray: number

      The value for the gray part of the color.

    • a: number

      The value for the alpha channel part of the color.

    Returns ColorGrayScaleAlpha

    The color in gray scale with alpha channel representation.

colorPalette

  • Create a new color of type ColorPalette.

    Parameters

    • index: number

      The value for the index on the palette.

    Returns ColorPalette

    The color in palette representation.

colorRGB

  • colorRGB(r: number, g: number, b: number): ColorRGB
  • Create a new color of type number.

    Parameters

    • r: number

      The value for the red part of the color.

    • g: number

      The value for the green part of the color.

    • b: number

      The value for the blue part of the color.

    Returns ColorRGB

    The color in rgb representation.

colorRGBA

  • colorRGBA(r: number, g: number, b: number, a: number): ColorRGBA
  • Create a new color of type number.

    Parameters

    • r: number

      The value for the red part of the color.

    • g: number

      The value for the green part of the color.

    • b: number

      The value for the blue part of the color.

    • a: number

      The value for the alpha channel part of the color.

    Returns ColorRGBA

    The color in rgba representation.

colorTypeToColorChecker

convertGrayScaleAlphaToRGBA

convertGrayScaleToRGBA

convertNativeBackgroundColor

  • Converts the background color from the libpng bindings into a color.

    Parameters

    • nativeBackgroundColor: any

      The background color as returned by the native bindings.

    • colorType: ColorType

      The color type of the image of which the background color should be converted.

    Returns ColorNoAlpha

    The converted background color in ColorRGB, ColorPalette or ColorGrayScale format or undefined if the background color was not set in the PNG.

convertNativePalette

  • convertNativePalette(nativePalette: any): Palette
  • Converts a native palette as returned by the bindings into a Map.

    Parameters

    • nativePalette: any

      The native palette which should be converted.

    Returns Palette

    The palette as a Palette (Javascript Map with the key being the palette index and the value being a color.

convertNativeTime

  • convertNativeTime(nativeTime: any): Date
  • Converts the native time from the libpng bindings into a javascript Date object.

    Parameters

    • nativeTime: any

      The time as returned by the bindings.

    Returns Date

    The time converted to a javascript Date object or undefined if the time was not set in the PNG's header.

convertPaletteToRGBA

  • Converts a color of type ColorPalette to ColorRGBA.

    Parameters

    • color: ColorPalette

      The color to convert.

    • palette: Palette

      The palette of the image the color originated from. Used to lookup the color.

    Returns ColorRGBA

    The converted color in rgba format.

convertRGBToRGBA

convertToRGBA

decode

  • Decode a buffer of encoded PNG data into a PngImage offering access to the raw image data.

    Parameters

    • buffer: Buffer

      The buffer to convert.

    Returns PngImage

    the decoded PNG as a PngImage instance.

defaultBackgroundColor

  • defaultBackgroundColor(colorType: ColorType): Object & object | Object & object | Object & object | Object & object | Object & object
  • Parameters

    Returns Object & object | Object & object | Object & object | Object & object | Object & object

encode

  • Encode a buffer of raw RGB or RGBA image data into PNG format. Only RGB and RGBA color formats are supported. This function will automatically calculate whether an alpha channel is present by calculating the amount of bytes per pixel from the length of the buffer and the provided width and height. Only 8bit colors are supported.

    Parameters

    • buffer: Buffer

      The buffer of raw pixel data to encode.

    • options: EncodeOptions

      Options used to encode the image.

    Returns Buffer

    the encoded PNG as a new buffer.

expectEveryPixel

expectRedBlueGradient

  • expectRedBlueGradient(data: Buffer): void

isColorGrayScale

  • isColorGrayScale(color: any): boolean
  • Checks if the given parameter is a color of type ColorGrayScale.

    Parameters

    • color: any

      The input to check.

    Returns boolean

    true if color was of type ColorGrayScale and false otherwise.

isColorGrayScaleAlpha

  • isColorGrayScaleAlpha(color: any): boolean
  • Checks if the given parameter is a color of type ColorGrayScaleA.

    Parameters

    • color: any

      The input to check.

    Returns boolean

    true if color was of type ColorGrayScaleA and false otherwise.

isColorPalette

  • isColorPalette(color: any): boolean
  • Checks if the given parameter is a color of type ColorPalette.

    Parameters

    • color: any

      The input to check.

    Returns boolean

    true if color was of type ColorPalette and false otherwise.

isColorRGB

  • isColorRGB(color: any): boolean
  • Checks if the given parameter is a color of type ColorRGB.

    Parameters

    • color: any

      The input to check.

    Returns boolean

    true if color was of type ColorRGB and false otherwise.

isColorRGBA

  • isColorRGBA(color: any): boolean
  • Checks if the given parameter is a color of type ColorRGBA.

    Parameters

    • color: any

      The input to check.

    Returns boolean

    true if color was of type ColorRGBA and false otherwise.

isPng

  • isPng(buffer: Buffer): boolean
  • Will check if the provided buffer contains a PNG image. Under the hood this will call png_sig_cmp and check for the header of the buffer.

    Parameters

    • buffer: Buffer

      The buffer to check.

    Returns boolean

    true if the file was a PNG image file and false otherwise.

isRect

  • isRect(toCheck: any): boolean
  • Checks if the given parameter is a rectangle.

    Parameters

    • toCheck: any

      Parameter to check.

    Returns boolean

    true if the given parameter was a rectangle and false otherwise.

isXY

  • isXY(coordinates: any): boolean
  • Checks if the given parameter is a set of 2D coordinates.

    Parameters

    • coordinates: any

      Parameter to check.

    Returns boolean

    true if the given parameter was a set of coordinates and false otherwise.

readPngFile

  • Invoke readPngFile to asynchroneously read a png file into a decoded image. For convenience, both Node.js callbacks and Promises are supported. If no callback is provided as a second argument, a Promise is returned which will resolve with the decoded image.

    Parameters

    • path: string

      The path to the file to decode.

    • callback: ReadPngFileCallback

      An optional callback to use instead of a returned Promise. Will be called with an error as the first argument or null if everything went well, and the decoded image as a second argument if no error occured.

    Returns void

    A Promise if no callback was provided and undefined otherwise.

  • Invoke readPngFile to asynchroneously read a png file into a decoded image. For convenience, both Node.js callbacks and Promises are supported. If no callback is provided as a second argument, a Promise is returned which will resolve with the decoded image.

    Parameters

    • path: string

      The path to the file to decode.

    Returns Promise<PngImage>

    A Promise if no callback was provided and undefined otherwise.

readPngFileSync

  • readPngFileSync(path: string): PngImage
  • Decode a PNG file synchroneously.

    Parameters

    • path: string

      The path to the file to decode.

    Returns PngImage

    The decoded image.

rect

  • rect(x: number, y: number, width: number, height: number): Rect
  • rect(offset: XY, dimensions: XY): Rect
  • Creates a rectangle.

    Parameters

    • x: number
    • y: number
    • width: number
    • height: number

    Returns Rect

    The created rectangle as an array with getters for the offset as coordinates or raw number as well as the dimensions.

  • Parameters

    • offset: XY
    • dimensions: XY

    Returns Rect

writePngFile

  • Invoke writePngFile to asynchroneously write a raw buffer of pixel data as an encoded PNG image. For convenience, both Node.js callbacks and Promises are supported. If no callback is provided as a second argument, a Promise is returned which will resolve once the file is written.

    Parameters

    • path: string

      The path the file should be written to.

    • buffer: Buffer

      The buffer of raw pixel data which should be encoded and written to disk.

    • options: EncodeOptions

      Options used to encode the image.

    • callback: WritePngFileCallback

      An optional callback to use instead of a returned Promise. Will be called with an error as the first argument or null if everything went well.

    Returns void

    A Promise if no callback was provided and undefined otherwise.

  • Invoke writePngFile to asynchroneously write a raw buffer of pixel data as an encoded PNG image. For convenience, both Node.js callbacks and Promises are supported. If no callback is provided as a second argument, a Promise is returned which will resolve once the file is written.

    Parameters

    • path: string

      The path the file should be written to.

    • buffer: Buffer

      The buffer of raw pixel data which should be encoded and written to disk.

    • options: EncodeOptions

      Options used to encode the image.

    Returns Promise<void>

    A Promise if no callback was provided and undefined otherwise.

writePngFileSync

  • writePngFileSync(path: string, buffer: Buffer, options: EncodeOptions): void
  • Encode and write a PNG file synchroneously.

    Parameters

    • path: string

      The path the file should be written to.

    • buffer: Buffer

      The buffer of raw pixel data which should be encoded and written to disk.

    • options: EncodeOptions

      Options used to encode the image.

    Returns void

    The decoded image.

xy

  • xy(x: number, y: number): XY
  • Creates a new set of 2D coordinates.

    Parameters

    • x: number

      The x part of the coordinates.

    • y: number

      The y part of the coordinates.

    Returns XY

    The new coordinates as an array which provides getters for x and y.

Generated using TypeDoc