Pixmap#

A Pixmap object contains a color raster image (short for pixel map). The components in a pixel in the Pixmap are all byte values, with the transparency as the last component.

A Pixmap also has a location (x, y) in addition to its size; so that they can easily be used to represent tiles of a page.

CONSTRUCTOR METHODS

Pixmap(colorspace: ColorSpace, bbox?: Rect, alpha: boolean = false)#

Create a new Pixmap. Note: The pixel data is not initialized.

Parameters:
Returns:

Pixmap.

EXAMPLE

var pixmap = new mupdfjs.Pixmap(mupdfjs.ColorSpace.DeviceRGB, [0,0,100,100], true);

INSTANCE METHODS

clear(value?: number)#

Clear the pixels to the specified value. Pass 255 for white, 0 for black, or omit for transparent.

Parameters:

valuenumber.

EXAMPLE

pixmap.clear(255);
getBounds()#

Return the pixmap bounds.

Returns:

Rect.

EXAMPLE

var rect = pixmap.getBounds();
getWidth()#
Returns:

number. The width value.

EXAMPLE

var w = pixmap.getWidth();
getHeight()#
Returns:

number. The height value.

EXAMPLE

var h = pixmap.getHeight();
getNumberOfComponents()#

Number of colors; plus one if an alpha channel is present.

Returns:

number. Number of color components.

EXAMPLE

var num = pixmap.getNumberOfComponents();
getAlpha()#

True if alpha channel is present.

Returns:

boolean.

EXAMPLE

var alpha = pixmap.getAlpha();
getStride()#

Number of bytes per row.

Returns:

number.

EXAMPLE

var stride = pixmap.getStride();
getColorSpace()#

Returns the ColorSpace for the Pixmap.

Returns:

ColorSpace.

EXAMPLE

var cs = pixmap.getColorSpace();
setResolution(x: number, y: number)#

Set x & y resolution.

Parameters:
  • xnumber. X resolution in dots per inch.

  • ynumber. Y resolution in dots per inch.

EXAMPLE

pixmap.setResolution(300, 300);
getXResolution()#

Returns the x resolution for the Pixmap.

Returns:

number. Resolution in dots per inch.

EXAMPLE

var xRes = pixmap.getXResolution();
getYResolution()#

Returns the y resolution for the Pixmap.

Returns:

number. Resolution in dots per inch.

EXAMPLE

var yRes = pixmap.getYResolution();
invert()#

Invert all pixels. All components are processed, except alpha which is unchanged.

EXAMPLE

pixmap.invert();
invertLuminance()#

Transform all pixels so that luminance of each pixel is inverted, and the chrominance remains as unchanged as possible. All components are processed, except alpha which is unchanged.

EXAMPLE

pixmap.invertLuminance();
gamma(p: number)#

Apply gamma correction to Pixmap. All components are processed, except alpha which is unchanged.

Values >= 0.1 & < 1 = darken, > 1 & < 10 = lighten.

Parameters:

pnumber.

EXAMPLE

pixmap.gamma(3.5);
tint(black: number | Color, white: number | Color)#
Tint all pixels in a RGB, BGR or Gray Pixmap.

Map black and white respectively to the given hex RGB values.

Parameters:
  • blacknumber | Color.

  • whitenumber | Color.

EXAMPLE

pixmap.tint(0xffff00, 0xffff00);
warp(points: Point[], width: number, height: number)#

Return a warped subsection of the Pixmap, where the result has the requested dimensions.

Parameters:
  • pointsPoint[]. Points give the corner points of a convex quadrilateral within the Pixmap to be warped.

  • widthnumber.

  • heightnumber.

Returns:

Pixmap.

EXAMPLE

var warpedPixmap = pixmap.warp([[0,0], [100,100], [130,170], [150,200]],200,200);
convertToColorSpace(colorspace: ColorSpace, keepAlpha: boolean = false)#

Convert pixmap into a new pixmap of a desired colorspace. A proofing colorspace, a set of default colorspaces and color parameters used during conversion may be specified. Finally a boolean indicates if alpha should be preserved (default is to not preserve alpha).

Parameters:
  • colorspaceColorspace.

  • keepAlphaboolean.

Returns:

Pixmap.

getPixels()#

Returns an array of pixels for the Pixmap.

Returns:

[...].

EXAMPLE

var pixels = pixmap.getPixels();
asPNG()#

Returns a buffer of the Pixmap as a PNG.

Returns:

Buffer.

EXAMPLE

var buffer = pixmap.asPNG();
asPSD()#

Returns a buffer of the Pixmap as a PSD.

Returns:

Buffer.

EXAMPLE

var buffer = pixmap.asPSD();
asPAM()#

Returns a buffer of the Pixmap as a PAM.

Returns:

Buffer.

EXAMPLE

var buffer = pixmap.asPAM();
asJPEG(quality: number, invert_cmyk: boolean)#

Returns a buffer of the Pixmap as a JPEG. Note, if the Pixmap has an alpha channel then an exception will be thrown.

Parameters:
  • qualitynumber. Should be between 0 - 100.

  • invert_cmykboolean.

Returns:

Buffer.

EXAMPLE

var buffer = pixmap.asJPEG(80, false);

Code samples

Code samples are in TypeScript and assume that the following requirements are defined in your TypeScript file header as follows:

import * as fs from "fs"
import * as mupdfjs from "mupdf/mupdfjs"