Function: getCanvasBoundingBox()
Call Signature
> getCanvasBoundingBox(options): Rectangle
Defined in: node_modules/pixi.js/lib/utils/canvas/getCanvasBoundingBox.d.ts:52
Internal
Measures the bounding box of a canvas's visible (non-transparent) pixels.
This function analyzes the alpha channel of the canvas pixels to find the smallest rectangle containing all non-transparent pixels. It's useful for optimizing sprite rendering by trimming transparent borders.
Uses an internal canvas with willReadFrequently: true for efficient pixel data access.
This internal canvas is reused between calls for better performance.
Parameters
options
The options for measuring the bounding box, including the canvas to measure.
Returns
The bounding box as a Rectangle containing the visible content. Returns Rectangle.EMPTY if the canvas is completely transparent.
Example
// Basic usage - get trim bounds at full resolution
const bounds = getCanvasBoundingBox({ canvas: myCanvas });
console.log(bounds); // Rectangle{x: 10, y: 5, width: 100, height: 200}
// Optimized for performance with lower resolution scanning
const fastBounds = getCanvasBoundingBox({
canvas: largeCanvas,
width: largeCanvas.width,
height: largeCanvas.height,
resolution: 0.5
});
// Resolution of 0.5 means scanning at half size, much faster for large canvases
// Using custom dimensions - only analyze part of the canvas
const partialBounds = getCanvasBoundingBox({ canvas: myCanvas, width: 100, height: 100 });
// Only analyzes a 100x100 region starting from top-left
Call Signature
> getCanvasBoundingBox(canvas, resolution?): Rectangle
Defined in: node_modules/pixi.js/lib/utils/canvas/getCanvasBoundingBox.d.ts:59
Internal
Parameters
canvas
resolution?
number
Returns
Deprecated
since 8.10.0