Pixen JavaScript API
    Preparing search index...

    Interface Layer

    A mutable pixel layer belonging to a canvas.

    interface Layer {
        name: string;
        visible: boolean;
        opacity: number;
        blendMode: BlendMode;
        size: Size;
        origin: Point;
        getPixel(x: number, y: number): Color | null;
        setPixel(x: number, y: number, color: Color): void;
        clear(color: Color): void;
        colorAtPoint(point: Point): Color | null;
        fillWithColor(color: Color): void;
        floodFillAtPoint(
            point: Point,
            color: Color,
            options?: FloodFillOptions | null,
        ): void;
        replaceColor(source: Color, destination: Color): void;
        translate(x: number, y: number): void;
        flip(direction: FlipDirection): void;
        rotate(degrees: number): void;
        resize(size: Size, options?: ResizeOptions | null): void;
        mergeDown(): boolean;
        drawLine(
            start: Point,
            end: Point,
            color: Color,
            options?: LineOptions | null,
        ): void;
        drawRectangle(rect: Rect, options: ShapeOptions): void;
        drawEllipse(rect: Rect, options: ShapeOptions): void;
        applyFilter(name: FilterName, options?: FilterOptions | null): boolean;
        applyCIFilterNamed(
            name: FilterName,
            parameters?: FilterOptions | null,
        ): boolean;
        writeToFile(path: string): boolean;
        duplicate(): Layer | null;
    }
    Index
    name: string

    User-visible layer name.

    visible: boolean

    Whether the layer participates in compositing.

    opacity: number

    Layer opacity from 0 through 1.

    blendMode: BlendMode

    Compositing mode selected from BlendMode.

    size: Size

    Layer bitmap dimensions in pixels.

    origin: Point

    Layer origin within the canvas coordinate system.

    • Parameters

      • x: number

        Horizontal pixel coordinate.

      • y: number

        Vertical pixel coordinate.

      Returns Color | null

      The layer color, or null off-canvas.

    • Parameters

      • x: number

        Horizontal pixel coordinate.

      • y: number

        Vertical pixel coordinate.

      • color: Color

        New pixel color.

      Returns void

    • Parameters

      • color: Color

        Color written to every pixel in the layer bitmap.

      Returns void

    • Parameters

      • point: Point

        Canvas pixel coordinate.

      Returns Color | null

      The layer color, or null off-canvas.

    • Parameters

      • color: Color

        Color used to fill the layer, respecting the current selection.

      Returns void

    • Flood-fills from a point.

      Parameters

      • point: Point

        Starting pixel coordinate.

      • color: Color

        Replacement color.

      • Optionaloptions: FloodFillOptions | null

        Fill tolerance and contiguous-region options.

      Returns void

    • Parameters

      • source: Color

        Color to replace.

      • destination: Color

        Replacement color.

      Returns void

    • Parameters

      • x: number

        Horizontal pixel delta.

      • y: number

        Vertical pixel delta.

      Returns void

    • Parameters

      • degrees: number

        Clockwise rotation in multiples of 90 degrees.

      Returns void

    • Parameters

      • size: Size

        New bitmap dimensions.

      • Optionaloptions: ResizeOptions | null

        Scaling algorithm and placement options.

      Returns void

    • Returns boolean

      Whether the layer was merged into the layer below it.

    • Parameters

      • start: Point

        Starting pixel coordinate.

      • end: Point

        Ending pixel coordinate.

      • color: Color

        Stroke color.

      • Optionaloptions: LineOptions | null

        Line width and pixel-perfect options.

      Returns void

    • Parameters

      • rect: Rect

        Shape bounds.

      • options: ShapeOptions

        Required stroke and/or fill colors plus stroke width.

      Returns void

    • Parameters

      • rect: Rect

        Shape bounds.

      • options: ShapeOptions

        Required stroke and/or fill colors plus stroke width.

      Returns void

    • Applies a named filter to this layer.

      Parameters

      Returns boolean

      Whether the filter was applied.

    • Applies a named filter to this layer.

      Parameters

      • name: FilterName

        A supported Pixen filter name.

      • Optionalparameters: FilterOptions | null

        Filter-specific options.

      Returns boolean

      Whether the filter was applied.

    • Parameters

      • path: string

        Destination path. Supported extensions are pxi, png, jpg, jpeg, gif, heic, tif, tiff, bmp, ico, svg, psd, and pntg.

      Returns boolean

      Whether the layer was written.

    • Returns Layer | null

      A new layer immediately above this one, or null if this layer is detached.