Skip to content

modern-pdf-lib


modern-pdf-lib / ImageOptimizeOptions

Interface: ImageOptimizeOptions

Defined in: src/assets/image/imageOptimize.ts:114

Combined options for the full optimization pipeline.

Extends

Properties

algorithm?

readonly optional algorithm: "nearest" | "bilinear" | "lanczos"

Defined in: src/assets/image/imageOptimize.ts:56

Resampling algorithm.

  • 'nearest': Nearest-neighbor (fast, blocky)
  • 'bilinear': Bilinear interpolation (good quality, moderate speed)
  • 'lanczos': Lanczos-3 resampling (best quality, slowest)

Default: 'bilinear'.

Inherited from

DownscaleOptions.algorithm


chromaSubsampling?

readonly optional chromaSubsampling: ChromaSubsampling

Defined in: src/assets/image/imageOptimize.ts:108

Chroma subsampling mode. Only used when format is 'jpeg'.

  • '4:4:4': No subsampling — best color fidelity, largest file.
  • '4:2:2': Horizontal subsampling — good balance.
  • '4:2:0': Both horizontal and vertical — smallest file.

Requires the JPEG WASM module to be initialized.

Default: '4:2:0'.

Inherited from

RecompressOptions.chromaSubsampling


compressionLevel?

readonly optional compressionLevel: 1 | 6 | 3 | 2 | 4 | 5 | 7 | 8 | 9

Defined in: src/assets/image/imageOptimize.ts:84

Deflate compression level (1–9). Only used when format is 'deflate'. Higher values produce smaller files but take longer.

Default: 6.

Inherited from

RecompressOptions.compressionLevel


format?

readonly optional format: "jpeg" | "deflate"

Defined in: src/assets/image/imageOptimize.ts:70

Output format.

  • 'jpeg': JPEG compression (lossy, good for photographs)
  • 'deflate': Deflate/zlib compression (lossless, used in PDF FlateDecode)

Default: 'deflate'.

Inherited from

RecompressOptions.format


maxHeight?

readonly optional maxHeight: number

Defined in: src/assets/image/imageOptimize.ts:28

Target maximum height in pixels. The image is scaled proportionally.

Inherited from

DownscaleOptions.maxHeight


maxWidth?

readonly optional maxWidth: number

Defined in: src/assets/image/imageOptimize.ts:26

Target maximum width in pixels. The image is scaled proportionally.

Inherited from

DownscaleOptions.maxWidth


printHeight?

readonly optional printHeight: number

Defined in: src/assets/image/imageOptimize.ts:47

Intended print height in points (1/72 inch). Used together with targetDpi to compute the target pixel dimensions.

Inherited from

DownscaleOptions.printHeight


printWidth?

readonly optional printWidth: number

Defined in: src/assets/image/imageOptimize.ts:42

Intended print width in points (1/72 inch). Used together with targetDpi to compute the target pixel dimensions.

Inherited from

DownscaleOptions.printWidth


progressive?

readonly optional progressive: boolean

Defined in: src/assets/image/imageOptimize.ts:96

Encode as progressive JPEG. Only used when format is 'jpeg'.

Progressive JPEGs render in multiple passes (low-res → full-res) which improves perceived loading speed on slow connections. They are also often slightly smaller than baseline JPEGs.

Requires the JPEG WASM module to be initialized.

Default: false.

Inherited from

RecompressOptions.progressive


quality?

readonly optional quality: number

Defined in: src/assets/image/imageOptimize.ts:77

JPEG quality (1–100). Only used when format is 'jpeg'. Higher values produce larger files with better quality.

Default: 85.

Inherited from

RecompressOptions.quality


skipBelowBytes?

readonly optional skipBelowBytes: number

Defined in: src/assets/image/imageOptimize.ts:121

Skip optimization if the input data is already smaller than this threshold (in bytes).

Default: 0 (always optimize).


targetDpi?

readonly optional targetDpi: number

Defined in: src/assets/image/imageOptimize.ts:37

Target DPI for the image at its intended print size. If specified along with printWidth / printHeight, the image is downscaled to match the target DPI.

For example, a 3000×2000 image printed at 10×6.67 inches would be 300 DPI. Setting targetDpi: 150 would downscale to 1500×1000.

Inherited from

DownscaleOptions.targetDpi

Released under the MIT License.