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, x2: 85, y1: 24.999999999999993, y2: 75 };

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
  • width: The width of the bounding box, returned from v3.3.97
  • height: The height of the bounding box, returned from v3.3.97
  • viewBox: The viewBox value that you can pass to an SVG, returned from v3.3.97

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​