Pixen JavaScript API
    Preparing search index...

    Interface Canvas

    A document or animation frame canvas.

    interface Canvas {
        size: Size;
        layers: readonly Layer[];
        activeLayer: Layer;
        selection: Selection;
        setSize(size: Size, anchor?: string | null): void;
        cropToRect(rect: Rect): void;
        scaleToSize(size: Size, options?: ScaleOptions | null): void;
        scaleToWidth(width: number): void;
        scaleToHeight(height: number): void;
        scaleWithPercentage(scale: number): void;
        trim(): void;
        flip(direction: FlipDirection): void;
        rotate(degrees: number): void;
        mergeVisibleLayers(): void;
        copyMerged(): void;
        supportedFilters(): readonly string[];
        applyFilter(name: FilterName, options?: FilterOptions | null): boolean;
        setActiveLayer(layer: Layer): void;
        addLayer(): Layer;
        insertLayerAtIndex(index: number): Layer | null;
        removeLayer(layer: Layer): boolean;
        moveLayer(layer: Layer, index: number): boolean;
        addImageLayer(path: string): Layer | null;
        insertImageLayerAtIndex(path: string, index: number): Layer | null;
        getPixel(x: number, y: number): Color | null;
        colorAtPoint(point: Point): Color | null;
        setPixel(x: number, y: number, color: Color): void;
        fill(color: Color): void;
        replaceColor(source: Color, destination: Color): void;
        removeAlpha(): void;
    }
    Index
    size: Size

    Canvas dimensions in pixels.

    layers: readonly Layer[]

    Layers ordered from bottom to top.

    activeLayer: Layer

    The layer that receives canvas-level editing commands.

    selection: Selection

    Selection state and commands.

    • Resizes the canvas without scaling layer pixels.

      Parameters

      • size: Size

        New positive pixel dimensions.

      • Optionalanchor: string | null

        Placement anchor for existing content, such as top left, center, or bottom right; defaults to top left.

      Returns void

    • Parameters

      • rect: Rect

        Rectangle that becomes the new canvas bounds.

      Returns void

    • Scales the canvas and its layers.

      Parameters

      • size: Size

        New positive pixel dimensions.

      • Optionaloptions: ScaleOptions | null

        Scaling algorithm options.

      Returns void

    • Parameters

      • width: number

        Positive target width; height is scaled proportionally.

      Returns void

    • Parameters

      • height: number

        Positive target height; width is scaled proportionally.

      Returns void

    • Parameters

      • scale: number

        Positive multiplier, where 0.5 is 50 percent.

      Returns void

    • Trims transparent outer rows and columns.

      Returns void

    • Parameters

      • degrees: number

        Clockwise rotation in multiples of 90 degrees.

      Returns void

    • Flattens visible layers into one layer.

      Returns void

    • Copies the composited canvas image to the system pasteboard.

      Returns void

    • Returns readonly string[]

      Filter names accepted by applyFilter().

    • Applies a named filter to the active layer.

      Parameters

      • name: FilterName

        A supported Pixen filter name.

      • Optionaloptions: FilterOptions | null

        Options specific to the selected filter.

      Returns boolean

      Whether the filter was applied.

    • Parameters

      • layer: Layer

        A layer belonging to this canvas.

      Returns void

    • Returns Layer

      A new layer appended above all existing layers.

    • Parameters

      • index: number

        Zero-based insertion index.

      Returns Layer | null

      The new layer, or null for an invalid index.

    • Parameters

      • layer: Layer

        A layer belonging to this canvas.

      Returns boolean

      Whether it was removed.

    • Parameters

      • layer: Layer

        A layer belonging to this canvas.

      • index: number

        Destination index.

      Returns boolean

      Whether it was moved.

    • Parameters

      • path: string

        Path to an image file.

      Returns Layer | null

      The inserted layer, or null on failure.

    • Parameters

      • path: string

        Path to an image file.

      • index: number

        Insertion index.

      Returns Layer | null

      The inserted layer, or null on failure.

    • Parameters

      • x: number

        Horizontal pixel coordinate.

      • y: number

        Vertical pixel coordinate.

      Returns Color | null

      The composited color, or null off-canvas.

    • Parameters

      • point: Point

        Canvas pixel coordinate.

      Returns Color | null

      The composited color, or null off-canvas.

    • Parameters

      • x: number

        Horizontal pixel coordinate.

      • y: number

        Vertical pixel coordinate.

      • color: Color

        New color for the active layer pixel.

      Returns void

    • Parameters

      • color: Color

        Color used to fill the active layer.

      Returns void

    • Parameters

      • source: Color

        Color to replace.

      • destination: Color

        Replacement color.

      Returns void

    • Makes every canvas pixel fully opaque.

      Returns void