### ImageMagick.read example with autoOrient, modulate, statistics, compare, and write Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image-methods-2.md Shows a typical workflow: read an image, auto-orient, modulate colors, get channel statistics, compare with another image, and write the result. Uses the 'rose:' built-in image and logs the red channel mean and distortion value. ```typescript ImageMagick.read('rose:', image => { image.autoOrient(); image.modulate(new Percentage(110), new Percentage(120), new Percentage(100)); const stats = image.statistics(Channels.RGB); console.log(stats.getChannel(PixelChannel.Red)?.mean); const distortion = ImageMagick.read('rose:', other => image.compare(other, ErrorMetric.RootMeanSquared)); console.log(distortion); image.write(MagickFormat.Jpeg, data => { /* copy data */ }); }); ``` -------------------------------- ### Magick.supportedFormats (get) Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets a lazily-loaded list of supported image formats as IMagickFormatInfo objects. ```APIDOC ## Magick.supportedFormats (get) ### Description Gets a lazily-loaded list of supported image formats as `IMagickFormatInfo` objects. ### Method GET ### Parameters None. ### Response - **supportedFormats** (ReadonlyArray) - The list of format information objects. ``` -------------------------------- ### MagickReadSettings usage example Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/settings.md Creates settings with frameIndex, frameCount, and width, then reads a collection of GIF frames. ```typescript const settings = new MagickReadSettings({ frameIndex: 2, frameCount: 5, width: 64, }); ImageMagick.readCollection(gifBytes, settings, images => { /* frames 2-6 resized to 64w */ }); ``` -------------------------------- ### MagickReadSettings Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/settings.md Documentation for the MagickReadSettings class, including constructor, properties, and usage example. ```APIDOC ## class `MagickReadSettings extends MagickSettings` ### Description Settings for reading images, extending `MagickSettings`. Allows specifying extraction area, frame selection, and size. ### Constructor `constructor(partialSettings?: Partial)` ### Properties - `extractArea` (`MagickGeometry | undefined`) - Area to extract when reading. - `frameIndex` (`number | undefined`) - First frame to read of a multi-frame image. - `frameCount` (`number | undefined`) - Number of frames to read (must be `1` for single-image `IMagickImage.read`). - `height` (`number | undefined`) - Set size height (with `width`). - `syncImageWithExifProfile` (`boolean`, default `true`) - Backed by define `exif:sync-image`. - `syncImageWithTiffProperties` (`boolean`, default `true`) - Backed by define `tiff:sync-image`. - `width` (`number | undefined`) - Set size width. ### Usage Example ```ts const settings = new MagickReadSettings({ frameIndex: 2, frameCount: 5, width: 64, }); ImageMagick.readCollection(gifBytes, settings, images => { /* frames 2-6 resized to 64w */ }); ``` ``` -------------------------------- ### Magick.delegates (get) Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets the ImageMagick delegate libraries string. ```APIDOC ## Magick.delegates (get) ### Description Gets the ImageMagick delegate libraries string. Returns `'Unknown'` if unavailable. ### Method GET ### Parameters None. ### Response - **delegates** (string) - The delegate libraries string. ``` -------------------------------- ### Example: getArea and setArea to tint red channel Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/pixels.md Reads an image, tints the red channel by adding 40, and writes back via setArea. ```typescript ImageMagick.read('rose:', image => { image.getPixels(pixels => { const area = pixels.getArea(0, 0, image.width, image.height); // tint the red channel: channel 0 for (let i = 0; i < area.length; i += image.channelCount) area[i] = Math.min(255, area[i] + 40); pixels.setArea(0, 0, image.width, image.height, area); }); image.write(MagickFormat.Png, data => { /* copy data */ }); }); ``` -------------------------------- ### Initialize ImageMagick with URL (browser) Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/image-magick.md Example of initializing ImageMagick using a URL in a browser environment. Throws a MagickError if the URL does not use http/https protocol. ```typescript // URL variant (browser) try { await initializeImageMagick(new URL('/magick.wasm', window.location.href)); } catch (error) { console.error('Initialization failed:', error); // MagickError if the URL uses a non-http(s) protocol } ``` -------------------------------- ### ImageMagick read with resize, blur, sharpen, write Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image-methods-1.md Example of using ImageMagick.read to load the 'logo:' image, then resizing, blurring, sharpening, and writing as PNG. The data callback receives the output data for copying. ```typescript ImageMagick.read('logo:', image => { image.resize(100, 100); image.blur(1, 5); image.sharpen(0, 1.2); image.write(MagickFormat.Png, data => { /* copy data */ }); }); ``` -------------------------------- ### MagickImageCollection.use Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image-collection.md Executes a callback with a MagickImageCollection instance, allowing operations on the collection. The example demonstrates reading, coalescing, per-frame resizing, and writing an animated GIF. ```APIDOC ## MagickImageCollection.use ### Description Executes a callback with a MagickImageCollection instance, allowing operations on the collection. The example demonstrates reading, coalescing, per-frame resizing, and writing an animated GIF. ### Method use ### Parameters - **callback** (function) - Required - A function that receives the MagickImageCollection instance. ### Example ```ts MagickImageCollection.use(images => { images.read(gifBytes, new MagickReadSettings({ frameCount: 10 })); images.coalesce(); // the collection itself has no resize — operate per frame: images.forEach(frame => frame.resize(64, 64)); images.write(MagickFormat.Gif, data => { /* copy animated gif */ }); }); ``` ### Errors - `MagickError('operation requires at least one image')` - Thrown when an operation that needs frames is called on an empty collection. - `MagickError('operation requires at least two images')` - Thrown when `morph` is called with fewer than 2 frames. - `MagickError` - Thrown for native failures during read/write/combine operations (marshaled). ``` -------------------------------- ### formatExpression() usage example Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image.md Example of using formatExpression to get a string with width, height, and pixel value at (0,0). ```typescript const text = image.formatExpression('%wx%h @ %[pixel:p{0,0}]'); ``` -------------------------------- ### write() with format and data copy Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image.md Example of using write() with a format and callback. The data buffer points into native memory and is released after the callback returns, so you must copy it (e.g., with data.slice()) if you need it later. ```typescript image.write(MagickFormat.Png, data => { const copy = data.slice(); // native memory is released after this function returns upload(copy); }); ``` -------------------------------- ### Using Quantum.max to create an opaque red color Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Shows how to use Quantum.max to get the maximum quantum value and create an opaque red MagickColor. The comment indicates that max is 255 for Q8 builds. ```TypeScript const max = Quantum.max; // 255 const red = new MagickColor(max, 0, 0, max); // opaque red ``` -------------------------------- ### Create and dispose an image Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image.md Example of creating a 300x200 red image, writing it as PNG, and disposing it in a finally block. The caller is responsible for disposing the image. ```typescript const image = MagickImage.create(MagickColors.Red, 300, 200); try { image.write(MagickFormat.Png, data => { /* keep a copy of data */ }); } finally { image.dispose(); } ``` -------------------------------- ### Initialize ImageMagick with byte array Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/image-magick.md Example of initializing ImageMagick using a Uint8Array read from a local file. This is the Uint8Array variant of the wasmLocationDataOrAssembly parameter. ```typescript import { initializeImageMagick } from '@imagemagick/magick-wasm'; import { readFileSync } from 'node:fs'; const wasmBytes = readFileSync('./node_modules/@dlemstra/magick-native/x86/magick.wasm'); await initializeImageMagick(wasmBytes); // Uint8Array variant ``` -------------------------------- ### Examples of creating MagickColor instances Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-color.md Creates a red opaque color, an RGBA color, a CMYK color, and a color from a hexadecimal string. ```typescript const red = new MagickColor(255, 0, 0); // opaque red const half = new MagickColor(255, 0, 0, 128); // RGBA const cmyk = new MagickColor(0, 255, 255, 0, 255); const byName = new MagickColor('#ff0000'); ``` -------------------------------- ### Example: toByteArray with 'I' mapping Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/pixels.md Reads the 'rose:' image and converts to a grayscale byte array using mapping 'I'. ```typescript ImageMagick.read('rose:', image => { const grayscale = image.getPixels(pixels => pixels.toByteArray(0, 0, image.width, image.height, 'I') ); // grayscale: Uint8Array | null }); ``` -------------------------------- ### Paths builder usage example Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/drawing.md Shows how to use the Paths builder to chain moveToAbs and lineToAbs calls and then convert to Drawables. The drawables() method wraps the accumulated IPath[] in a DrawablePath. ```typescript const paths = new Paths() .moveToAbs(10, 10) .lineToAbs(90, 10) .lineToAbs(90, 90) .drawables(); // Drawables containing one DrawablePath ``` -------------------------------- ### Fuzzy comparison example Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-color.md Compares two MagickColor instances using fuzzyEquals with a fuzz value of 10, returning true or false depending on the fuzz tolerance. ```typescript const a = new MagickColor(255, 0, 0); const b = new MagickColor(254, 2, 4); console.log(a.fuzzyEquals(b, new Percentage(10))); // true/false depending on fuzz ``` -------------------------------- ### initializeImageMagick(wasmLocationDataOrAssembly, configurationFiles?) Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/image-magick.md Initializes the singleton ImageMagick instance using the x86 build of the native library. Loads the wasm module, writes configuration files into the virtual filesystem, sets MAGICK_CONFIGURE_PATH=/xml, and calls _Environment_Initialize. ```APIDOC ## initializeImageMagick(wasmLocationDataOrAssembly, configurationFiles?) ### Description Initializes the singleton `ImageMagick` instance using the **x86** build of the native library (`MagickNativex86`). Loads the wasm module, writes the configuration files into the virtual filesystem, sets `MAGICK_CONFIGURE_PATH=/xml` and calls `_Environment_Initialize`. ### Method Function (async) ### Signature ```ts export async function initializeImageMagick( wasmLocationDataOrAssembly: URL | ByteArray | WebAssembly.Module, configurationFiles?: IConfigurationFiles ): Promise ``` ### Parameters #### wasmLocationDataOrAssembly - **URL** - Required - Must use `http:`/`https:` protocol, otherwise `MagickError('Only http/https protocol is supported')` is thrown synchronously. The URL is used as `locateFile` result. - **ByteArray** (`Int8Array | Uint8Array | Uint8ClampedArray`) - Required - Passed as `wasmBinary` directly to the Emscripten module factory. - **WebAssembly.Module** - Required - Instantiated directly via `new WebAssembly.Instance(module, imports)`. #### configurationFiles - **IConfigurationFiles** - Optional - Defaults to `ConfigurationFiles.default` (`log.xml` + `policy.xml`). See [../configuration.md](../configuration.md). ### Behavior - Repeated calls are **no-ops**: `_initialize` returns immediately when `this.api !== undefined`. - Any failure is rejected as a `Promise` rejection (`MagickError` when thrown inside). ### Request Example ```ts import { initializeImageMagick } from '@imagemagick/magick-wasm'; import { readFileSync } from 'node:fs'; const wasmBytes = readFileSync('./node_modules/@dlemstra/magick-native/x86/magick.wasm'); await initializeImageMagick(wasmBytes); // Uint8Array variant ``` ```ts // URL variant (browser) try { await initializeImageMagick(new URL('/magick.wasm', window.location.href)); } catch (error) { console.error('Initialization failed:', error); // MagickError if the URL uses a non-http(s) protocol } ``` ### Response #### Success Response - **Promise** - Resolves when initialization is complete. #### Error Handling - **MagickError** - Thrown synchronously if the URL uses a non-http(s) protocol. - **Promise rejection** - Any failure during initialization is rejected as a Promise rejection. ``` -------------------------------- ### CompareSettings Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/settings.md Documentation for the CompareSettings class, including constructor, properties, and notes. ```APIDOC ## class `CompareSettings` ### Description Settings for image comparison, used with `MagickImage.compare`. ### Constructor `constructor(metric: ErrorMetric)` ### Properties - `readonly metric` (`ErrorMetric`) - The error metric used for comparison. - `highlightColor?` (`IMagickColor`) - Color for highlighted differences. - `lowlightColor?` (`IMagickColor`) - Color for lowlight differences. - `masklightColor?` (`IMagickColor`) - Color for masklight differences. ### Notes Colors map to temporary artifacts `compare:highlight-color` / `compare:lowlight-color` / `compare:masklight-color`. ``` -------------------------------- ### Magick.imageMagickVersion (get) Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets the ImageMagick version string, with 'Unknown' as fallback. ```APIDOC ## Magick.imageMagickVersion (get) ### Description Gets the ImageMagick version string, with `'Unknown'` as fallback. ### Method GET ### Parameters None. ### Response - **imageMagickVersion** (string) - The version string. ``` -------------------------------- ### Custom IConfigurationFiles and initializeImageMagick Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/configuration.md Shows how to create a custom IConfigurationFiles object with log and policy XML data and pass it to initializeImageMagick. The 'all' generator yields the files, and the data strings are written verbatim to the wasm filesystem. Note that ConfigurationFiles has a private constructor, so use ConfigurationFiles.default or build an IConfigurationFiles yourself. ```typescript import { ConfigurationFiles, initializeImageMagick } from '@imagemagick/magick-wasm'; const files: IConfigurationFiles = { all: function* () { yield { fileName: 'log.xml', data: '' }; yield { fileName: 'policy.xml', data: '...' }; }, log: { fileName: 'log.xml', data: '' }, policy: { fileName: 'policy.xml', data: '...' }, }; await initializeImageMagick(wasmBytes, files); ``` -------------------------------- ### Magick.features (get) Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets the ImageMagick features string with trailing space stripped. ```APIDOC ## Magick.features (get) ### Description Gets the ImageMagick features string with trailing space stripped. ### Method GET ### Parameters None. ### Response - **features** (string) - The features string. ``` -------------------------------- ### readCollection usage example Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/image-magick.md Example usage of readCollection to count the frames in a GIF byte array. The callback receives the collection and returns the number of frames. ```typescript const frameCount = ImageMagick.readCollection(gifBytes, MagickFormat.Gif, images => images.length); ``` -------------------------------- ### readFromCanvas usage example Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/image-magick.md Example usage of readFromCanvas to rotate the canvas image by 90 degrees and write it as a PNG. The callback receives the image and can perform operations before it is disposed. ```typescript ImageMagick.readFromCanvas(canvasEl, image => { image.rotate(90); image.write(MagickFormat.Png, data => { /* upload data */ }); }); ``` -------------------------------- ### floodFill(...) — 5 overloads Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image-methods-2.md Fills a contiguous region of the image with a specified color or alpha value, starting from a given point. Overloads allow specifying alpha, color, target color, or using an image as the fill source. ```APIDOC ## floodFill(...) ### Description Fills a contiguous region with a specified color or alpha value starting at a given coordinate. ### Method void ### Signatures ```ts floodFill(alpha: number, x: number, y: number): void; floodFill(color: IMagickColor, x: number, y: number): void; floodFill(color: IMagickColor, x: number, y: number, target: IMagickColor): void; floodFill(image: IMagickImage, x: number, y: number): void; floodFill(image: IMagickImage, x: number, y: number, target: IMagickColor): void; ``` ### Parameters #### alpha / color / image - **alpha** (number) - Required (for alpha overload) - The alpha value to fill with. - **color** (IMagickColor) - Required (for color overloads) - The fill color. - **image** (IMagickImage) - Required (for image overloads) - The image used as fill source. #### x, y - **x** (number) - Required - The x-coordinate of the starting point. - **y** (number) - Required - The y-coordinate of the starting point. #### target (optional) - **target** (IMagickColor) - Optional - The target color to fill. When omitted, the color at `(x, y)` is sampled first via the pixel collection. ``` -------------------------------- ### initializeImageMagickx64 function signature Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/image-magick.md Loads the x64 build of the WASM library. Use when the wasm file is `dist/x64/magick.wasm` (export `@imagemagick/magick-wasm/x64/magick.wasm`). ```ts export async function initializeImageMagickx64( wasmLocationDataOrAssembly: URL | ByteArray | WebAssembly.Module, configurationFiles?: IConfigurationFiles ): Promise ``` -------------------------------- ### Example: appendHorizontally usage Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image-collection.md Example showing how to use appendHorizontally within MagickImageCollection.use. Reads gifBytes, appends horizontally, writes the result as PNG, and returns the width. The result is a number if sync, otherwise 'async'. ```typescript const count = MagickImageCollection.use(images => { images.read(gifBytes); return images.appendHorizontally(image => { image.write(MagickFormat.Png, data => { /* copy */ }); return image.width; }); }); console.log(typeof count === 'number' ? count : 'async'); ``` -------------------------------- ### ResourceLimits.width Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets or sets the maximum width of an image. ```APIDOC ## GET/PUT ResourceLimits.width ### Description Gets or sets the maximum width of an image. ### Method GET/PUT ### Endpoint `ResourceLimits.width` (static getter/setter) ### Parameters #### Request Body (for PUT) - **value** (bigint) - Required - The maximum width. ### Response #### Success Response (200) - **value** (bigint) - The current maximum width. #### Response Example ```json { "value": 16384 } ``` ``` -------------------------------- ### ResourceLimits.height Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets or sets the maximum height of an image. ```APIDOC ## GET/PUT ResourceLimits.height ### Description Gets or sets the maximum height of an image. ### Method GET/PUT ### Endpoint `ResourceLimits.height` (static getter/setter) ### Parameters #### Request Body (for PUT) - **value** (bigint) - Required - The maximum height. ### Response #### Success Response (200) - **value** (bigint) - The current maximum height. #### Response Example ```json { "value": 16384 } ``` ``` -------------------------------- ### getPixel Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/pixels.md Gets the raw pixel values at a single coordinate. ```APIDOC ## `getPixel(x, y)` ### Description Gets the raw pixel values at the specified coordinates as a 1×1 area. ### Method `getPixel` ### Signature `getPixel(x: number, y: number): quantumArray` ### Parameters - `x` (number) - Required - The x-coordinate of the pixel. - `y` (number) - Required - The y-coordinate of the pixel. ### Returns - `quantumArray` - A writable `Uint8Array` view into native memory containing the pixel's channel values. ``` -------------------------------- ### Iterate supported formats and log PNG info Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Loops through Magick.supportedFormats and logs the MIME type and version for formats that support reading and match the PNG format. ```TypeScript for (const info of Magick.supportedFormats) { if (info.supportsReading && info.format === MagickFormat.Png) console.log(info.mimeType, info.version); } ``` -------------------------------- ### DrawableLine Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/drawing.md Draws a line from a start point to an end point. ```APIDOC ## DrawableLine ### Description Draws a line from a start point to an end point. ### Constructor `(startX, startY, endX, endY)` ### Getter(s) - `startX` - `startY` - `endX` - `endY` ``` -------------------------------- ### static _create (internal) Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image.md Internal helper that creates an image, runs a callback, and disposes afterwards. Public surface ImageMagick.read and friends are built on it. ```APIDOC ## static _create (internal) ### Description Internal helper: creates an image, runs the callback, disposes afterwards. Public surface `ImageMagick.read` and friends are built on it. ### Method static _create ### Signatures - `static _create(func: SyncImageCallback): TReturnType;` - `static _create(func: AsyncImageCallback): Promise;` ### Parameters - **func** (SyncImageCallback | AsyncImageCallback) - Required - Callback that receives the created image. Can be synchronous or asynchronous. ### Returns - **TReturnType** - The return value of the callback. - **Promise** - If the callback is asynchronous, a promise resolving to the callback's return value. ### Remarks This method is marked `@internal` and is not intended for direct public use. ``` -------------------------------- ### ResourceLimits.listLength Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets or sets the maximum number of images in an image list. ```APIDOC ## GET/PUT ResourceLimits.listLength ### Description Gets or sets the maximum number of images in an image list. ### Method GET/PUT ### Endpoint `ResourceLimits.listLength` (static getter/setter) ### Parameters #### Request Body (for PUT) - **value** (bigint) - Required - The maximum number of images. ### Response #### Success Response (200) - **value** (bigint) - The current maximum number of images. #### Response Example ```json { "value": 100 } ``` ``` -------------------------------- ### ResourceLimits.disk Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets or sets the pixel cache disk limit in bytes. ```APIDOC ## GET/PUT ResourceLimits.disk ### Description Gets or sets the pixel cache disk limit in bytes. ### Method GET/PUT ### Endpoint `ResourceLimits.disk` (static getter/setter) ### Parameters #### Request Body (for PUT) - **value** (bigint) - Required - The disk limit in bytes. ### Response #### Success Response (200) - **value** (bigint) - The current disk limit. #### Response Example ```json { "value": 1073741824 } ``` ``` -------------------------------- ### ResourceLimits.time Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets or sets the maximum number of seconds the process may execute. ```APIDOC ## GET/PUT ResourceLimits.time ### Description Gets or sets the maximum number of seconds the process may execute. ### Method GET/PUT ### Endpoint `ResourceLimits.time` (static getter/setter) ### Parameters #### Request Body (for PUT) - **value** (bigint) - Required - The maximum number of seconds. ### Response #### Success Response (200) - **value** (bigint) - The current time limit. #### Response Example ```json { "value": 60 } ``` ``` -------------------------------- ### ResourceLimits.maxProfileSize Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets or sets the max profile size in bytes that can be added to an image. ```APIDOC ## GET/PUT ResourceLimits.maxProfileSize ### Description Gets or sets the max profile size in bytes that can be added to an image. ### Method GET/PUT ### Endpoint `ResourceLimits.maxProfileSize` (static getter/setter) ### Parameters #### Request Body (for PUT) - **value** (bigint) - Required - The max profile size in bytes. ### Response #### Success Response (200) - **value** (bigint) - The current max profile size. #### Response Example ```json { "value": 65536 } ``` ``` -------------------------------- ### ping(...) — two overloads Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image.md Same as read but only metadata is parsed; no pixel data is loaded. Pixel access afterwards fails. ```APIDOC ## ping(...) — two overloads ### Description Same as `read` but only metadata is parsed; no pixel data is loaded. Pixel access afterwards fails (`getPixels` throws `MagickError('image contains no pixel data')`). ### Method ping ### Signatures - `ping(fileName: string, settings?: MagickReadSettings): void;` - `ping(array: ByteArray, settings?: MagickReadSettings): void;` ### Parameters #### Overload 1: fileName, settings? - **fileName** (string) - Required - The file name or ImageMagick pseudo-format expression to ping. - **settings** (MagickReadSettings) - Optional - Read settings. #### Overload 2: array, settings? - **array** (ByteArray) - Required - Byte array containing image data. - **settings** (MagickReadSettings) - Optional - Read settings. ### Returns - **void** - This method does not return a value. ### Errors - Pixel access afterwards fails: `getPixels` throws `MagickError('image contains no pixel data')`. ``` -------------------------------- ### Initialize ImageMagick with wasmBytes Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/index.md Must be called exactly once per page/process before any API call. Until it resolves, every access to ImageMagick._api throws MagickError('`await initializeImageMagick` should be called to initialize the library'). ```typescript import { initializeImageMagick, readFileSync } from '...'; // readFileSync from node:fs const wasmBytes = readFileSync('./magick.wasm'); await initializeImageMagick(wasmBytes); ``` -------------------------------- ### ResourceLimits.maxMemoryRequest Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets or sets the max memory request in bytes. Larger allocations are memory-mapped. ```APIDOC ## GET/PUT ResourceLimits.maxMemoryRequest ### Description Gets or sets the max memory request in bytes. Larger allocations are memory-mapped. ### Method GET/PUT ### Endpoint `ResourceLimits.maxMemoryRequest` (static getter/setter) ### Parameters #### Request Body (for PUT) - **value** (bigint) - Required - The max memory request in bytes. ### Response #### Success Response (200) - **value** (bigint) - The current max memory request. #### Response Example ```json { "value": 1048576 } ``` ``` -------------------------------- ### static create(array?) Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image-collection.md Creates a new MagickImageCollection. If a byte array is provided, all frames are read immediately. The caller owns the returned collection and must dispose it. ```APIDOC ## static create(array?) ### Description Creates a new MagickImageCollection. If a byte array is provided, all frames are read immediately. The caller owns the returned collection and must dispose it. ### Method static ### Signature ```ts static create(): IMagickImageCollection; static create(array: ByteArray): IMagickImageCollection; ``` ### Parameters - **array** (ByteArray) - Optional - Byte array containing image data. If provided, all frames are read immediately. ### Returns - **IMagickImageCollection** - The created collection. The caller must call `dispose()` on it. ### Example ```ts const images = MagickImageCollection.create(gifBytes); try { /* ... */ } finally { images.dispose(); } ``` ``` -------------------------------- ### Quantum.depth Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets the quantum depth (e.g., 8 or 16) used by the current build of ImageMagick. ```APIDOC ## GET Quantum.depth ### Description Returns the quantum depth (e.g., 8 or 16) used by the current build of ImageMagick. ### Method GET ### Endpoint `Quantum.depth` (static getter) ### Parameters None ### Response #### Success Response (200) - **value** (number) - The quantum depth. #### Response Example ```json { "value": 8 } ``` ``` -------------------------------- ### static create(...) — four overloads Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image.md Creates a new native image. With a color/width/height the image is filled with the color. With a file name or byte array it is read immediately. Without arguments an empty image is created. The returned image must be disposed by the caller. ```APIDOC ## static create(...) — four overloads ### Description Creates a new native image. With a color/width/height the image is filled with the color (reads the built-in `xc:` pseudo-image). With a file name or byte array it is read immediately (full read, not a ping). Without arguments an empty image is created. The returned image must be disposed by the caller. ### Method static create ### Signatures - `static create(): IMagickImage;` - `static create(color: IMagickColor, width: number, height: number): IMagickImage;` - `static create(fileName: string, settings?: MagickReadSettings): IMagickImage;` - `static create(array: ByteArray, settings?: MagickReadSettings): IMagickImage;` ### Parameters #### Overload 1: No arguments - No parameters. #### Overload 2: color, width, height - **color** (IMagickColor) - Required - The color to fill the image with. - **width** (number) - Required - The width of the image in pixels. - **height** (number) - Required - The height of the image in pixels. #### Overload 3: fileName, settings? - **fileName** (string) - Required - The file name or ImageMagick pseudo-format expression to read. - **settings** (MagickReadSettings) - Optional - Read settings. #### Overload 4: array, settings? - **array** (ByteArray) - Required - Byte array containing image data. - **settings** (MagickReadSettings) - Optional - Read settings. ### Returns - **IMagickImage** - The created image. Must be disposed by the caller. ### Example ```ts const image = MagickImage.create(MagickColors.Red, 300, 200); try { image.write(MagickFormat.Png, data => { /* keep a copy of data */ }); } finally { image.dispose(); } ``` ### Errors - Calling methods that need pixel data on an empty image throws from the native layer. ``` -------------------------------- ### quantize(settings?) Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image-collection.md Like the single-image version, returns `MagickErrorInfo` when `measureErrors`, else `null`. ```APIDOC ## quantize(settings?) ### Description Like the single-image version, returns `MagickErrorInfo` when `measureErrors`, else `null`. ### Method quantize ### Signature ts quantize(settings?: QuantizeSettings): MagickErrorInfo | null; ### Parameters - **settings** (QuantizeSettings) - Optional - Quantization settings. ### Returns - `MagickErrorInfo` when `measureErrors` is set, otherwise `null`. ``` -------------------------------- ### Retrieve Image Statistics Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/profiles-and-statistics.md Example of retrieving statistics for specific channels and accessing channel data. ```ts const stats = image.statistics(Channels.RGB); console.log(stats.getChannel(PixelChannel.Red)?.mean, stats.composite().standardDeviation); ``` -------------------------------- ### Read and resize image with sync callback Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/image-magick.md Reads an image from a file name (e.g., 'logo:') and resizes it to 100x100, then writes it as JPEG and logs the data length. The image is disposed automatically after the callback completes. ```ts ImageMagick.read('logo:', image => { image.resize(100, 100); image.write(MagickFormat.Jpeg, data => { console.log(data.length); }); }); ``` -------------------------------- ### ProgressEvent callback usage Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/profiles-and-statistics.md Example of using the onProgress callback to abort an operation when progress exceeds 50%. ```ts image.onProgress = event => { if (event.progress.toDouble() > 50) { event.cancel = true; return 0; } return 1; }; ``` -------------------------------- ### PathMoveToRel Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/drawing.md Creates a path move-to relative command. ```APIDOC ## PathMoveToRel ### Description Creates a path move-to relative command that moves the current point by the specified offsets. ### Constructor `new PathMoveToRel(x: number, y: number)` ### Parameters - **x** (number) - Required - The x-offset for the move. - **y** (number) - Required - The y-offset for the move. ### Usage ```ts const path = new PathMoveToRel(10, 20); ``` ``` -------------------------------- ### Calculate Perceptual Hash Distance Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/profiles-and-statistics.md Example of calculating the sum squared distance between two perceptual hashes. ```ts const hash1 = image.perceptualHash(); const hash2 = other.perceptualHash(); console.log(hash1.sumSquaredDistance(hash2), hash1.toString()); ``` -------------------------------- ### static create() overloads Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image-collection.md Shows the two overloads of the static create method. The first takes no arguments and returns an empty collection. The second takes a ByteArray and reads all frames immediately. ```typescript static create(): IMagickImageCollection; static create(array: ByteArray): IMagickImageCollection; ``` -------------------------------- ### IStatistics Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/profiles-and-statistics.md Interface for accessing channel statistics from a MagickImage. Provides methods to get composite statistics or statistics for a specific channel. ```APIDOC ## IStatistics ### Description Interface for accessing channel statistics from a MagickImage. Provides methods to get composite statistics or statistics for a specific channel. ### Methods - **composite()** - Returns the composite channel statistics. - **getChannel(channel: PixelChannel)** - Returns statistics for the specified channel, or null if not available. ### Properties - **channels** (ReadonlyArray) - The list of channels included in the statistics. ### Usage Example ```ts const stats = image.statistics(Channels.RGB); console.log(stats.getChannel(PixelChannel.Red)?.mean, stats.composite().standardDeviation); ``` ``` -------------------------------- ### Create MagickImageInfo and log dimensions Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Creates a MagickImageInfo from PNG bytes with a frame index setting and logs the width, height, format, and quality. ```TypeScript const info = MagickImageInfo.create(pngBytes, { frameIndex: 0 } as MagickReadSettings); console.log(`${info.width}x${info.height} ${info.format} q${info.quality}`); ``` -------------------------------- ### Configure .npmrc with GitHub personal access token Source: https://github.com/dlemstra/magick-wasm/blob/main/CONTRIBUTING.md Add this line to your .npmrc file to authenticate with the GitHub package registry. Replace YOUR_PERSONAL_ACCESS_TOKEN with a token that has the read:packages scope. ```ini //npm.pkg.github.com/:_authToken=YOUR_PERSONAL_ACCESS_TOKEN ``` -------------------------------- ### Get color profile and log description/colorSpace Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/profiles-and-statistics.md Retrieves the color profile from an image and logs its description and color space if present. ```typescript const profile = image.getColorProfile(); if (profile !== null) { console.log(profile.description, profile.colorSpace); } ``` -------------------------------- ### ResourceLimits.memory Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets or sets the pixel cache memory limit in bytes. Beyond it all pixel cache operations go to/from disk. ```APIDOC ## GET/PUT ResourceLimits.memory ### Description Gets or sets the pixel cache memory limit in bytes. Beyond it all pixel cache operations go to/from disk. ### Method GET/PUT ### Endpoint `ResourceLimits.memory` (static getter/setter) ### Parameters #### Request Body (for PUT) - **value** (bigint) - Required - The memory limit in bytes. ### Response #### Success Response (200) - **value** (bigint) - The current memory limit. #### Response Example ```json { "value": 268435456 } ``` ``` -------------------------------- ### Using use() with a callback Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick-image-collection.md Creates an empty collection, runs the callback, and disposes the collection (and its images) afterwards. The callback receives the collection and can read images into it. ```typescript MagickImageCollection.use(images => { images.read(gifBytes); return images.length; }); ``` -------------------------------- ### Read and resize image with async callback Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/image-magick.md Reads a PNG from a `Uint8Array` with an async callback, resizes to 64x64, writes the result as PNG, and returns the data length. The image is disposed automatically after the awaited callback completes. ```ts const size = await ImageMagick.read(new Uint8Array(pngBytes), MagickFormat.Png, async image => { await image.resize(64, 64); let result = 0; await image.write(MagickFormat.Png, data => { result = data.length; }); return result; }); ``` -------------------------------- ### Quantum.max Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets the maximum quantum value (e.g., 255 for Q8, 65535 for Q16). Used to interpret quantum-typed pixel arrays. ```APIDOC ## GET Quantum.max ### Description Returns the maximum quantum value (e.g., 255 for Q8, 65535 for Q16). This value is used to interpret quantum-typed pixel arrays. ### Method GET ### Endpoint `Quantum.max` (static getter) ### Parameters None ### Response #### Success Response (200) - **value** (number) - The maximum quantum value. #### Response Example ```json { "value": 255 } ``` ``` -------------------------------- ### CompareSettings constructor and properties Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/settings.md Constructor and properties for CompareSettings, used with MagickImage.compare. ```typescript constructor(metric: ErrorMetric); readonly metric: ErrorMetric; highlightColor?: IMagickColor; lowlightColor?: IMagickColor; masklightColor?: IMagickColor; ``` -------------------------------- ### ResourceLimits.area Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Gets or sets the maximum width * height of an image that may reside in the pixel cache memory. Larger images are cached to disk. ```APIDOC ## GET/PUT ResourceLimits.area ### Description Gets or sets the maximum width * height of an image that may reside in the pixel cache memory. Larger images are cached to disk. ### Method GET/PUT ### Endpoint `ResourceLimits.area` (static getter/setter) ### Parameters #### Request Body (for PUT) - **value** (bigint) - Required - The area limit. ### Response #### Success Response (200) - **value** (bigint) - The current area limit. #### Response Example ```json { "value": 150994944 } ``` ``` -------------------------------- ### QuantizeSettings Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/settings.md Settings for quantize and remap operations. ```APIDOC ## class `QuantizeSettings` ### Description Settings for `quantize`/`remap` operations. ### Constructor `constructor()` - defaults: colors=256, colorSpace=ColorSpace.Undefined, ditherMethod=DitherMethod.Riemersma, measureErrors=false, treeDepth=0 ### Properties - `colors` (number) - Number of colors. - `colorSpace` (ColorSpace) - Color space. - `ditherMethod` (DitherMethod | undefined) - Dither method. - `measureErrors` (boolean) - Measure errors. - `treeDepth` (number) - Tree depth. ``` -------------------------------- ### IPerceptualHash Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/profiles-and-statistics.md Interface for perceptual hash operations. Provides methods to get channel hashes, compute sum of squared distances, and convert to string. ```APIDOC ## IPerceptualHash ### Description Interface for perceptual hash operations. Provides methods to get channel hashes, compute sum of squared distances, and convert to string. ### Methods - **getChannel(channel: number)** - Returns the channel perceptual hash for the given channel index, or null if not available. - **sumSquaredDistance(other: IPerceptualHash)** - Computes the sum of squared distances between this hash and another. - **toString()** - Returns the string representation of the hash. ### Constructor Overloads - `constructor(hash: string)` - Creates a hash from a string. - `constructor(hash: string, colorSpaces: ReadonlyArray)` - Creates a hash from a string with specified color spaces. - `constructor(red: ChannelPerceptualHash, green: ChannelPerceptualHash, blue: ChannelPerceptualHash)` - Internal constructor. ### Validation Errors - `MagickError('Invalid hash size')` when the string length mismatches `3 * 35 * colorSpaces.length`. - `MagickError('Invalid number of colorspaces, the minimum is 1 and the maximum is 6')`. - `MagickError('Specifying the same colorspace more than once is not allowed')`. - `MagickError('Invalid hash specified')` for non-hex tokens. ### Usage Example ```ts const hash1 = image.perceptualHash(); const hash2 = other.perceptualHash(); console.log(hash1.sumSquaredDistance(hash2), hash1.toString()); ``` ``` -------------------------------- ### Create and use MagickGeometry with flags Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/types.md Creates a MagickGeometry with width and height, sets the fillArea and ignoreAspectRatio flags, and logs the resulting geometry string '100x100^!'. The geometry is then passed to image.resize(). ```typescript const g = new MagickGeometry(100, 100); g.fillArea = true; g.ignoreAspectRatio = true; console.log(g.toString()); // '100x100^!' image.resize(g); ``` -------------------------------- ### MagickImageInfo static create method signature Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/magick.md Static convenience method that constructs a MagickImageInfo and calls read on it. ```TypeScript static create(array: ByteArray, settings?: MagickReadSettings): IMagickImageInfo ``` -------------------------------- ### PathLineToRel Source: https://github.com/dlemstra/magick-wasm/blob/main/_autodocs/api-reference/drawing.md Creates a path line-to relative command. ```APIDOC ## PathLineToRel ### Description Creates a path line-to relative command that draws a line from the current point by the specified offsets. ### Constructor `new PathLineToRel(x: number, y: number)` ### Parameters - **x** (number) - Required - The x-offset for the line endpoint. - **y** (number) - Required - The y-offset for the line endpoint. ### Usage ```ts const path = new PathLineToRel(10, 20); ``` ```