Skip to main content

getBoundingBox()v3.3.40

Part of the @remotion/paths package.

Returns the bounding box of the given path, suitable for calculating the viewBox value that you need to pass to an SVG.

The bounding box is the smallest rectangle which can contain the shape in full.

get-bounding-box.ts
import { getBoundingBox } from "@remotion/paths"; const boundingBox = getBoundingBox( "M 35,50 a 25,25,0,1,1,50,0 a 25,25,0,1,1,-50,0" ); // { x1: 35, y1: 24.999999999999993, x2: 85, y2: 75, viewBox: "35 24.999999999999993 50 50.00000000000001", width: 50, height: 50.00000000000001 }

This function will throw if the SVG path is invalid.

Return type​

Includes the following properties:

x1​

The leftmost x coordinate of the bounding box.

x2​

The rightmost x coordinate of the bounding box.

y1​

The topmost y coordinate of the bounding box.

y2​

The bottommost y coordinate of the bounding box.

widthv3.3.97​

The width of the bounding box.

heightv3.3.97​

The height of the bounding box.

viewBoxv3.3.97​

The viewBox value that you can pass to an SVG.

BoundingBox type​

In TypeScript, you can get the shape of the return value by importing the BoundingBox type:

import type { BoundingBox } from "@remotion/paths";

Compatibility​

BrowsersServersEnvironments
Chrome
Firefox
Safari
Node.js
Bun
Serverless Functions

See also​