Global

Members

(constant) DEFAULT_CHARSET :string

Description:
  • Standard character set ordered from densest (darkest) to sparsest (lightest).

Source:

Standard character set ordered from densest (darkest) to sparsest (lightest).

Type:
  • string

(constant) ImageAreaSelector

Description:
  • ImageAreaSelector - An interactive image cropping tool.

    Displays an image with a draggable selection box to define a crop area. The selected crop area can be dragged to another part of the image before applying. Constraints applied: image boundaries, optional aspect ratio, and prevents negative dimensions.

Source:

ImageAreaSelector - An interactive image cropping tool.

Displays an image with a draggable selection box to define a crop area. The selected crop area can be dragged to another part of the image before applying. Constraints applied: image boundaries, optional aspect ratio, and prevents negative dimensions.

Example
```tsx
const [crop, setCrop] = useState<CropArea>({ x: 0, y: 0, width: 0, height: 0 });

<ImageAreaSelector
  src="image.jpg"
  aspect={16 / 9}
  lineColor="#00ff00"
  onCropChange={setCrop}
/>
```

(constant) ImageCropper

Description:
  • ImageCropper - A complete image cropping interface with explicit apply.

    Combines the ImageAreaSelector for interactive crop area selection with LuminaCanvas for rendering the applied crop in the same component after the user clicks Apply.

    Props summary (not exhaustive):

    • src: Image source (string | File | HTMLImageElement | HTMLCanvasElement | ImageData | null)
    • onCropComplete: Callback when crop is finalized (receives Blob or DataURL)
    • onError: Callback for processing errors
    • aspectRatio: Optional aspect ratio to enforce (width / height)
    • outputFormat: 'blob' | 'dataUrl'
    • showPreview: show the applied crop result in place after Apply. Set false for parent-managed previews.
    • allowReset: show reset button
    • allowResize: show resize handles on the selected crop area
    • applyButtonClassName / applyButtonStyle: Customize the Apply button class/style
    • resetButtonClassName / resetButtonStyle: Customize the Reset button class/style
    • selector* and *ClassName/*Style props: Theme overlay, handles, controls, and error states
    • onApply / onReset: Optional callbacks fired when Apply or Reset are clicked. If the callback returns false (or a Promise that resolves to false), the default behavior is aborted.

    Accessibility notes:

    • Keyboard support is available for an existing crop region (arrow move, Shift+arrow larger move, Alt+arrow resize, Enter confirm, Escape clear).
    • Pointer interactions (dragging/handles) remain primary for geometric selection.
Source:

ImageCropper - A complete image cropping interface with explicit apply.

Combines the ImageAreaSelector for interactive crop area selection with LuminaCanvas for rendering the applied crop in the same component after the user clicks Apply.

Props summary (not exhaustive):

  • src: Image source (string | File | HTMLImageElement | HTMLCanvasElement | ImageData | null)
  • onCropComplete: Callback when crop is finalized (receives Blob or DataURL)
  • onError: Callback for processing errors
  • aspectRatio: Optional aspect ratio to enforce (width / height)
  • outputFormat: 'blob' | 'dataUrl'
  • showPreview: show the applied crop result in place after Apply. Set false for parent-managed previews.
  • allowReset: show reset button
  • allowResize: show resize handles on the selected crop area
  • applyButtonClassName / applyButtonStyle: Customize the Apply button class/style
  • resetButtonClassName / resetButtonStyle: Customize the Reset button class/style
  • selector* and *ClassName/*Style props: Theme overlay, handles, controls, and error states
  • onApply / onReset: Optional callbacks fired when Apply or Reset are clicked. If the callback returns false (or a Promise that resolves to false), the default behavior is aborted.

Accessibility notes:

  • Keyboard support is available for an existing crop region (arrow move, Shift+arrow larger move, Alt+arrow resize, Enter confirm, Escape clear).
  • Pointer interactions (dragging/handles) remain primary for geometric selection.
Example
```tsx
<ImageCropper
  src="photo.jpg"
  aspectRatio={16 / 9}
  outputFormat="blob"
  applyButtonClassName="primary-btn"
  resetButtonStyle={{ backgroundColor: '#fff' }}
  onApply={(crop) =>  validate crop or return false to prevent default }
  onReset={() => /* do custom reset; return false to prevent default }
/>
```

(constant) LUMA_B :number

Description:
  • Luminance weight for the Blue channel

Source:

Luminance weight for the Blue channel

Type:
  • number

(constant) LUMA_G :number

Description:
  • Luminance weight for the Green channel

Source:

Luminance weight for the Green channel

Type:
  • number

(constant) LUMA_R :number

Description:
  • Luminance weight for the Red channel

Source:

Luminance weight for the Red channel

Type:
  • number

(constant) LuminaCanvas

Description:
  • LuminaCanvas - A declarative React component to render LuminaJS processed images on a canvas.

    This component handles the rendering of image transformations directly onto an HTML <canvas>. It provides a powerful, prop-driven interface to apply image edits like crop, resize, and various filters. You can also access the resulting generated image using the getImage callback prop.

Source:

LuminaCanvas - A declarative React component to render LuminaJS processed images on a canvas.

This component handles the rendering of image transformations directly onto an HTML <canvas>. It provides a powerful, prop-driven interface to apply image edits like crop, resize, and various filters. You can also access the resulting generated image using the getImage callback prop.

Example
```tsx
function App() {
  const handleImage = (dataUrl) => console.log('Generated Image:', dataUrl);

  return (
    <LuminaCanvas
      source="photo.jpg"
      brightness={20}
      sepia={true}
      resize={{ width: 500, height: 500 }}
      outputType="dataUrl"
      getImage={handleImage}
      width={500} // standard canvas attribute
      height={500} // standard canvas attribute
    />
  );
}
```

(constant) applyConvolution

Description:
  • Generic Convolution Engine Performance notes:

    • Convolution traverses almost every pixel and applies kernel math per pixel.
    • Repeated passes or large images can block the main thread.
    • Prefer resizing before convolution when running live previews.
Source:

Generic Convolution Engine Performance notes:

  • Convolution traverses almost every pixel and applies kernel math per pixel.
  • Repeated passes or large images can block the main thread.
  • Prefer resizing before convolution when running live previews.

(constant) edgeDetection

Source:

(constant) emboss

Source:

(constant) sharpen

Source:

Methods

ImageCropperExample()

Description:
  • Complete image cropper example demonstrating:

    • Basic cropping with ImageCropper component
    • Resizing an existing crop area with selection handles
    • Custom aspect ratios
    • Handling the cropped result
    • Combining ImageAreaSelector with useLumina for custom workflows
Source:

applyEditingOptions(chain, options)

Description:
  • Applies the provided ImageEditingOptions to a Lumina instance.

Source:
Parameters:
Name Type Description
chain

The Lumina chain instance

options

The options to apply

Returns:

The modified Lumina chain instance

ascii(imageData, optionsopt) → {string}

Description:
  • Converts the provided ImageData into an ASCII string representation.

    Note: For best results, the input ImageData should be relatively low resolution (e.g., 50-100 pixels wide), as each pixel maps to a single character.

Source:
Example
const { getResizedImageData } = Lumina;
const smallData = getResizedImageData(image, 80, 40);
const textOutput = ascii(smallData);
console.log(textOutput);
Parameters:
Name Type Attributes Default Description
imageData ImageData

The source pixel data.

options Object <optional>
{}

Transformation options.

Properties
Name Type Attributes Default Description
charSet string <optional>
'@%#*+=-:. '

A string of characters ordered from dark to light.

invert boolean <optional>
false

If true, treats the first character as the lightest.

Returns:

A string containing the ASCII representation of the image, including newlines.

Type
string

assertBrowserEnvironment(operation)

Description:
  • Throws a deterministic error in non-browser runtimes.

Source:
Parameters:
Name Type Description
operation string

backgroundBlur(imageData, optionsopt) → {ImageData}

Description:
  • Applies a background blur effect to a copy of the provided ImageData.

    Performance notes:

    • This filter is heavier than plain blur because it computes a full blur pass and then composites per pixel with distance-based weighting.
    • Large source images can noticeably block the main thread.
    • For interactive focus controls, use a smaller preview resolution first, then apply full-resolution processing only for final output.
Source:
Example
const portrait = backgroundBlur(imageData, { sigma: 8, focusRadius: 100 });
Parameters:
Name Type Attributes Default Description
imageData ImageData

The source pixel data.

options Object <optional>
{}

Customization options.

Properties
Name Type Attributes Default Description
sigma number <optional>
5

Blur intensity for the background.

centerX number <optional>

X coordinate of the focus center (default: center).

centerY number <optional>

Y coordinate of the focus center (default: center).

focusRadius number <optional>

Radius of the perfectly sharp area (default: 20% of min dimension).

falloff number <optional>

Distance over which the blur reaches maximum (default: 40% of min dimension).

Returns:

A new ImageData object with the selective blur applied.

Type
ImageData

blur(imageData, radius) → {ImageData}

Description:
  • Applies a box blur filter to a copy of the provided ImageData. This implementation uses a two-pass box blur algorithm (horizontal then vertical) for better performance.

    Performance notes:

    • Runtime cost grows with image dimensions and blur radius.
    • Large images can block the main thread during interactive use.
    • For responsive UIs, resize first (preview), then run full-resolution blur only on final export.
Source:
Example
const blurredData = blur(imageData, 3);
Parameters:
Name Type Description
imageData ImageData

The source pixel data.

radius number

The blur radius (integer). Default is 1.

Returns:

A new ImageData object with blur applied.

Type
ImageData

brightness(imageData, level) → {ImageData}

Description:
  • Applies a brightness filter to a copy of the provided ImageData.

Source:
Example
const brightData = brightness(imageData, 50);
Parameters:
Name Type Description
imageData ImageData

The source pixel data.

level number

Brightness adjustment level.

  • level > 0: Increases brightness.
  • level < 0: Decreases brightness (darker).
  • Recommended range: [-255, 255].
Returns:

A new ImageData object with adjusted brightness.

Type
ImageData

canvasToBlob(canvas, mimeTypeopt, qualityopt) → {Promise.<Blob>}

Description:
  • Converts a canvas element to a Blob asynchronously. A convenience wrapper around the native canvas.toBlob callback API.

Source:
Example
const blob = await canvasToBlob(canvas, 'image/jpeg', 0.85);
const url = URL.createObjectURL(blob);
Parameters:
Name Type Attributes Default Description
canvas HTMLCanvasElement

The source canvas.

mimeType string <optional>
'image/png'

Output MIME type (e.g. 'image/jpeg').

quality number <optional>
0.92

Compression quality for lossy formats (0.0–1.0).

Throws:

Rejects if the browser fails to encode the canvas.

Type
Error
Returns:

Resolves with the encoded image Blob.

Type
Promise.<Blob>

clamp(value, min, max) → {number}

Description:
  • Clamps a numeric value to a given inclusive range [min, max].

Source:
Example
clamp(300, 0, 255); // → 255
clamp(-10, 0, 255); // → 0
clamp(128, 0, 255); // → 128
Parameters:
Name Type Description
value number

The input value.

min number

Lower bound (inclusive).

max number

Upper bound (inclusive).

Returns:

The clamped value.

Type
number

contrast(imageData, level) → {ImageData}

Description:
  • Applies a contrast filter to a copy of the provided ImageData.

Source:
Example
const highContrastData = contrast(imageData, 30);
Parameters:
Name Type Description
imageData ImageData

The source pixel data.

level number

Contrast adjustment level.

  • level > 0: Increases contrast.
  • level < 0: Decreases contrast.
  • Range: [-100, 100].
Returns:

A new ImageData object with adjusted contrast.

Type
ImageData

createOffscreenCanvas(width, height) → {CanvasContext}

Description:
  • Creates an offscreen canvas sized to the given dimensions.

Source:
Parameters:
Name Type Description
width number

Canvas width in pixels.

height number

Canvas height in pixels.

Returns:

An object containing the canvas and its 2D context.

Type
CanvasContext

crop(source, x, y, width, height) → {HTMLCanvasElement}

Description:
  • Crops an image or canvas. Returns a new canvas with the cropped content.

Source:
Parameters:
Name Type Description
source HTMLImageElement | HTMLCanvasElement

The source to crop.

x number

Left coordinate.

y number

Top coordinate.

width number

Crop width.

height number

Crop height.

Returns:

A new canvas containing the cropped image.

Type
HTMLCanvasElement

gaussianBlur(imageData, sigma) → {ImageData}

Description:
  • Applies a Gaussian blur filter to a copy of the provided ImageData. This implementation uses a two-pass separable convolution for better performance.

    Performance notes:

    • Runtime increases with image size and sigma.
    • Sigma also increases kernel radius (ceil(sigma * 3)), which raises compute cost.
    • On large images this can block the main thread; prefer preview resizing and/or Web Worker offload.
Source:
Example
const blurredData = gaussianBlur(imageData, 3.5);
Parameters:
Name Type Description
imageData ImageData

The source pixel data.

sigma number

The standard deviation of the Gaussian distribution. Larger values result in more blurring. Default is 2.

Returns:

A new ImageData object with Gaussian blur applied.

Type
ImageData

getPixelData(image) → {Object}

Description:
  • Draws an HTMLImageElement onto an offscreen canvas and returns the raw pixel data as an ImageData object.

    The returned ImageData.data is a flat Uint8ClampedArray of RGBA values: [R, G, B, A, R, G, B, A, ...], where each channel is in the range [0, 255].

Source:
Example
const img = await loadImage('photo.jpg');
const { imageData, canvas } = getPixelData(img);
// imageData.data => Uint8ClampedArray [R, G, B, A, ...]
Parameters:
Name Type Description
image HTMLImageElement

A fully loaded image element. It must have non-zero naturalWidth and naturalHeight properties.

Throws:

Throws if the image has zero dimensions or if the canvas context cannot be obtained (e.g. context already in use).

Type
Error
Returns:

An object containing the extracted ImageData and the offscreen canvas used, which can be passed to putPixelData after manipulation.

Type
Object

getResizedImageData(image, width, height) → {ImageData}

Description:
  • Extracts ImageData from an image after resizing it to the specified dimensions. Useful for filters that require downsampling, like ASCII art.

Source:
Parameters:
Name Type Description
image HTMLImageElement

The source image.

width number

Target width.

height number

Target height.

Returns:

The extracted pixel data at the new resolution.

Type
ImageData

grayscale(imageData) → {ImageData}

Description:
  • Applies a grayscale filter to a cloned copy of the provided ImageData.

    Each pixel's RGB channels are replaced with the luminance value Y, computed via the BT.601 formula. The alpha channel is preserved unchanged.

    Performance notes:

    • Pixel array length is cached before the loop to avoid repeated property lookups.
    • The loop increments by 4 on every iteration (one full RGBA pixel per step), eliminating redundant index arithmetic.
    • A new ImageData is returned; the original is never mutated.
Source:
Example
import { loadImage }    from '../core/loader.js';
import { getPixelData, putPixelData, canvasToBlob } from '../core/canvas.js';
import { grayscale }    from '../filters/grayscale.js';

const img              = await loadImage(file);
const { imageData, canvas } = getPixelData(img);
const grayData         = grayscale(imageData);

putPixelData(canvas, grayData);
const blob = await canvasToBlob(canvas);
Parameters:
Name Type Description
imageData ImageData

The source pixel data, as returned by getPixelData.

Returns:

A new ImageData object with all pixels converted to grayscale.

Type
ImageData

instanceOfGlobal(value, globalName) → {boolean}

Description:
  • Safe instanceof check for browser globals that may be undefined in SSR.

Source:
Parameters:
Name Type Description
value unknown
globalName string
Returns:
Type
boolean

isBrowserEnvironment() → {boolean}

Description:
  • Returns true when canvas/DOM primitives are available. Evaluated at call time so test environments that install globals later still behave like a browser runtime.

Source:
Returns:
Type
boolean

isImageFile(value) → {boolean}

Description:
  • Returns true if the provided value is a File object whose MIME type indicates an image format.

Source:
Example
isImageFile(event.target.files[0]); // → true / false
Parameters:
Name Type Description
value unknown

Any value to test.

Returns:

true if value is an image File, otherwise false.

Type
boolean

loadFromFile(file) → {Promise.<HTMLImageElement>}

Description:
  • Loads an image from a File object by creating a temporary object URL. The object URL is revoked automatically after the image has loaded to prevent memory leaks.

Source:
Parameters:
Name Type Description
file File

A File object, typically from an element.

Throws:
  • Rejects if the provided File is not a valid image MIME type.

    Type
    TypeError
  • Rejects if the image fails to load from the generated object URL.

    Type
    Error
Returns:

Resolves with a fully loaded HTMLImageElement.

Type
Promise.<HTMLImageElement>

loadFromURL(url) → {Promise.<HTMLImageElement>}

Description:
  • Loads an image from a URL string.

Source:
Parameters:
Name Type Description
url string

A fully-qualified image URL or a data URL.

Throws:

Rejects if the image fails to load (e.g. 404, CORS block).

Type
Error
Returns:

Resolves with a fully loaded HTMLImageElement.

Type
Promise.<HTMLImageElement>

loadImage(source) → {Promise.<HTMLImageElement>}

Description:
  • Loads an image from either a URL string or a File object, returning a Promise that resolves to an HTMLImageElement.

    This is the primary entry point for image ingestion in LuminaJS.

Source:
Examples
// Load from URL
const img = await loadImage('<image url string>');
// Load from File input
const [file] = event.target.files;
const img = await loadImage(file);
Parameters:
Name Type Description
source string | File

The image source. Accepts:

  • string: A URL (absolute, relative, or data URL).
  • File: A File object from the browser File API.
Throws:

Rejects if source is neither a string nor a File.

Type
TypeError
Returns:

A promise that resolves to a fully loaded HTMLImageElement, ready for canvas drawing.

Type
Promise.<HTMLImageElement>

lumina(source) → {Lumina}

Description:
  • Initiates a chainable processing sequence.

Source:
Parameters:
Name Type Description
source string | File | HTMLImageElement | HTMLCanvasElement | ImageData

The image source.

Returns:

A new Lumina chain instance.

Type
Lumina

putPixelData(canvas, imageData) → {void}

Description:
  • Writes an ImageData object back onto a canvas element, replacing its current contents. This is the inverse of getPixelData and is used to commit mutated pixel data back to a drawable surface.

Source:
Example
const { imageData, canvas } = getPixelData(img);
// ... mutate imageData.data ...
putPixelData(canvas, imageData);
const dataURL = canvas.toDataURL('image/png');
Parameters:
Name Type Description
canvas HTMLCanvasElement

The target canvas. Typically the one returned from a prior getPixelData call, already sized to match the data.

imageData ImageData

The pixel data to write. Its width and height must not exceed the canvas dimensions.

Throws:

Throws if a 2D context cannot be obtained from the canvas.

Type
Error
Returns:
Type
void

resize(source, width, height) → {HTMLCanvasElement}

Description:
  • Resizes an image or canvas to new dimensions. Returns a new canvas with the resized content.

Source:
Parameters:
Name Type Description
source HTMLImageElement | HTMLCanvasElement

The source to resize.

width number

New width.

height number

New height.

Returns:

A new canvas containing the resized image.

Type
HTMLCanvasElement

sepia(imageData) → {ImageData}

Description:
  • Applies a sepia filter to a copy of the provided ImageData.

Source:
Example
const sepiaData = sepia(imageData);
Parameters:
Name Type Description
imageData ImageData

The source pixel data.

Returns:

A new ImageData object with sepia tones applied.

Type
ImageData

useLumina(options) → {UseLuminaResult.<T>}

Description:
  • useLumina - A powerful and declarative React hook for image processing.

    This hook manages the entire lifecycle of an image, applying advanced filters and transformations seamlessly while providing loading and error states. You can process images via explicit props, or utilize the operations callback for more complex chainable API logic.

Source:
Example
```tsx
const { result, loading, getImage } = useLumina({
  source: 'photo.jpg',
  grayscale: true,
  brightness: 20,
  outputType: 'dataUrl',
  deps: [] // dependencies that trigger a re-run
});

// Get the image on demand (e.g., in an onClick handler)
const uploadImage = async () => {
  const blob = await getImage('blob');
  await api.upload(blob);
};
```
Parameters:
Name Type Description
options UseLuminaOptions

Configuration options for the hook.

Properties
Name Type Attributes Default Description
source LuminaSource | null

The image source (URL, File, HTMLImageElement, HTMLCanvasElement, or ImageData).

operations function <optional>

Optional callback to use Lumina's chainable API manually.

deps Array.<unknown> <optional>
[]

Array of dependencies that should trigger a re-render.

outputType LuminaOutputType <optional>
'imageData'

The format of the returned result ('imageData', 'dataUrl', 'blob').

grayscale boolean <optional>

Apply a grayscale filter.

brightness number <optional>

Adjust image brightness.

blur number <optional>

Apply a box blur effect.

resize Object <optional>

Resize the image { width, height }. // ... and many other filters (sepia, contrast, sharpen, etc.)

Returns:

The processing state containing result, loading, error, and an imperative getImage function.

Type
UseLuminaResult.<T>

watermark(imageData, text, optionsopt) → {ImageData}

Description:
  • Applies a text watermark to a copy of the provided ImageData.

Source:
Example
const watermarked = watermark(imageData, '© LuminaJS', { x: 20, y: 20, color: 'white' });
Parameters:
Name Type Attributes Default Description
imageData ImageData

The source pixel data.

text string

The watermark text to overlay.

options Object <optional>
{}

Customization options.

Properties
Name Type Attributes Default Description
x number <optional>
10

X coordinate for the text.

y number <optional>
10

Y coordinate for the text.

fontSize number <optional>
24

Font size in pixels.

fontFace string <optional>
'Arial'

Font family name.

font string <optional>
'24px Arial'

CSS font string (overrides fontSize/fontFace).

color string <optional>
'rgba(255, 255, 255, 0.5)'

CSS color string.

align CanvasTextAlign <optional>
'left'

Text alignment ('left', 'center', 'right', 'start', 'end').

baseline CanvasTextBaseline <optional>
'top'

Text baseline ('top', 'hanging', 'middle', 'alphabetic', 'ideographic', 'bottom').

Returns:

A new ImageData object with the watermark applied.

Type
ImageData

Type Definitions

CanvasContext

Source:
Properties:
Name Type Description
canvas HTMLCanvasElement

The offscreen canvas element.

ctx CanvasRenderingContext2D

The 2D rendering context.

Type:
  • Object