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.
Create a new empty Pixmap whose pixel data is not initialized. Alternatively create a new Pixmap based on an existing Pixmap without alpha and combine it with a single component soft mask of the same dimensions.
ColorSpace | null) – The
desired colorspace for the new pixmap. null implies a
single component alpha pixmap.Rect) – The desired dimensions of
the new pixmap.boolean) – Whether the new
pixmap should have an alpha component.Pixmap)
– The original pixmap without alpha.Pixmap) –
Soft mask used as alpha in the combined pixmap.var pixmap1 = new mupdf.Pixmap(mupdf.ColorSpace.DeviceRGB, [0, 0, 100, 100], true)
var pixmap2 = new mupdf.Pixmap(
new mupdf.Image("photo.png").toPixmap(),
new mupdf.Image("softmask.png").toPixmap()
)Clear the pixels to the specified value. Pass 255 for white, 0 for black, or omit for transparent.
number) – The value to use for
clearing.pixmap.clear(255)Return the pixmap bounds.
var rect = pixmap.getBounds()Get the width of the pixmap.
var w = pixmap.getWidth()Get the height of the pixmap.
var h = pixmap.getHeight()Number of colors; plus one if an alpha channel is present.
var num = pixmap.getNumberOfComponents()Returns whether an alpha channel is present.
var alpha = pixmap.getAlpha()Number of bytes per row.
var stride = pixmap.getStride()Returns the colorspace of this pixmap. Returns null if the pixmap has no colors (for example if it is an opacity mask with only an alpha channel).
var cs = pixmap.getColorSpace()Set horizontal and vertical resolution.
number) – Horizontal resolution in
dots per inch.number) – Vertical resolution in
dots per inch.pixmap.setResolution(300, 300)Returns the x coordinate of the pixmap.
var x = pixmap.getX()Returns the y coordinate of the pixmap.
var y = pixmap.getY()Returns the horizontal resolution in dots per inch for this pixmap.
var xRes = pixmap.getXResolution()Returns the vertical resolution in dots per inch for this pixmap.
var yRes = pixmap.getYResolution()Invert all pixels. All components are processed, except alpha which is unchanged.
pixmap.invert()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.
pixmap.invertLuminance()Apply gamma correction to this pixmap. All components are processed, except alpha which is unchanged.
Values >= 0.1 & < 1 darkens the pixmap,
> 1 & < 10 lightens the pixmap.
number) – Desired gamma level.pixmap.gamma(3.5)Tint all pixels in RGB, BGR or Gray pixmaps. Map black and white respectively to the given hex RGB values.
Color | number) – Map black to
this color.Color | number) – Map white to
this color.pixmap.tint(0xffff00, 0xffff00)Return a warped subsection of this pixmap, where the corner of the input quadrilateral will be “warped” to become the four corner points of the returned pixmap defined by the requested dimensions.
var warpedPixmap = pixmap.warp([[0, 0], [100, 100], [130, 170], [150, 200]], 200, 200)only mutool run
Same as Pixmap.prototype.warp()
except that width and height are automatically determined.
var warpedPixmap = pixmap.autowarp([0,0,100,0,0,100,100,100])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).
ColorSpace) – The
desired colorspace.boolean) – Whether to keep
the alpha component.Returns an array of pixels for this pixmap.
var pixels = pixmap.getPixels()Returns a buffer of this pixmap as a PNG.
var buffer = pixmap.asPNG()Returns a buffer of this pixmap as a PSD.
var buffer = pixmap.asPSD()Returns a buffer of this pixmap as a PAM.
var buffer = pixmap.asPAM()Returns a buffer of this pixmap as a JPEG. Note, if this pixmap has an alpha channel then an exception will be thrown.
number) – Desired compression
quality, between 0 and 100.number) – How to handle
polarity in CMYK
JPEG images (0: non-inverted, 1: inverted, 2: convert to RGB).var buffer = pixmap.asJPEG(80, 2)only mutool run
Decodes a barcode detected in the pixmap, and returns an object with properties for barcode type and contents.
number) – Degrees of rotation
to rotate pixmap before detecting barcode. Defaults to 0.var barcodeInfo = displayList.decodeBarcode([0, 0, 100, 100 ], 0)only mutool run
Encodes a barcode into a pixmap. The supported types of barcode is either one of:
| Matrix | Linear Product | Linear Industrial | |||
|---|---|---|---|---|---|
| String | Name | String | Name | String | Name |
qrcode |
QR Code | upca |
UPC-A | code39 |
Code 39 |
microqrcode |
Micro QR Code | upce |
UPC-E | code93 |
Code 93 |
rmqrcode |
rMQR Code | ean8 |
EAN-8 | code128 |
Code 128 |
aztec |
Aztec | ean13 |
EAN-13 | codabar |
Codabar |
datamatrix |
DataMatrix | databar |
DataBar | databarexpanded |
DataBar Expanded |
pdf417 |
PDF417 | databarlimited |
DataBar Limited | dxfilmedge |
DX Film Edge |
maxicode |
MaxiCode | itf |
ITF |
string) – The desired
barcode type.string) – The textual
content to encode into the barcode.number) – The size of the
barcode in pixels.number) – The
error correction level (0-8).boolean) – Whether to add
an empty margin around the barcode.boolean) – Whether
to add human-readable text. Some barcodes, e.g. EAN-13, can have the
barcode contents printed in human-readable text next to the
barcode.var pix = Pixmap.encodeBarcode("qrcode", "Hello world!", 100, 2, true, false)only mutool run
Get the value of component index at position x, y
(relative to the image origin: 0, 0 is the top left pixel).
number) – X coordinate.number) – Y coordinate.number) – Component index.
i.e. For CMYK ColorSpaces 0 = Cyan, 3 = Black, for RGB 0 = Red, 2 ==
Blue etc.// Get green component of pixel at 10, 10
var sample = rgbpixmap.getSample(10, 10, 1)only mutool run
Save this Pixmap as a PNG. Only works for gray and RGB images.
string) – Desired name of
image file.pixmap.saveAsPNG("filename.png")only mutool run
Save this Pixmap as a JPEG file. Only works for gray, RGB and CMYK images.
string) – Desired name of
image file.number) – Desired quality
between 0 and 100. Defaults to 90.pixmap.saveAsJPEG("filename.jpg", 80)only mutool run
Save this Pixmap as a PAM file.
string) – Desired name of
image file.pixmap.saveAsPAM("filename.pam")only mutool run
Save this Pixmap as a PNM file. Only works for gray and RGB images without alpha.
string) – Desired name of
image file.pixmap.saveAsPNM("filename.pnm")only mutool run
Save this Pixmap as a PBM file. Only works for alpha only, gray and CMYK images without alpha.
string) – Desired name of
image file.pixmap.saveAsPBM("filename.pbm")only mutool run
Save this Pixmap as a PKM file. Only works for alpha only, gray and CMYK images without alpha.
string) – Desired name of
image file.pixmap.saveAsPKM("filename.pkm")only mutool run
Save this Pixmap as a JPX file.
string) – Desired name of
image file.number) – Desired quality
between 0 and 100. Defaults to 90.pixmap.saveAsJPX("filename.jpx", 90)only mutool run
Detect a “document” in a Pixmap. Only a grayscale Pixmap without alpha is supported, anything else will cause an exception to be thrown.
Returns null if no document was detected.
var documentLocation = pixmap.detectDocument([0,0,100,0,100,100,0,100])only mutool run
Returns the angle of skew detected from Pixmap. Note, if the Pixmap is not Greyscale with no alpha then an exception will be thrown.
var angle = pixmap.detectSkew()only mutool run
Returns a new Pixmap being the deskewed version of the supplied Pixmap. Note, if a Pixmap is supplied that is not RGB or Greyscale, or has alpha then an exception will be thrown.
number) – The angle to
deskew.string) – “increase” increases
the size of the pixmap so no pixels are lost. “maintain” maintains the
size of the pixmap. “decrease” decreases the size of the page so no new
pixels are shown.var deskewed = pixmap.deskew(angle, 0)only mutool run
Returns the MD5 digest of the pixmap pixel data. The digest is returned as a string of 16 hex digits.
var md5 = pixmap.computeMD5()