Skip to content

🎥 Make videos programmatically with React

scalePath()

Jonny Burger2919fc9c3d51
diff --git a/packages/docs/components/TableOfContents/paths.tsx b/packages/docs/components/TableOfContents/paths.tsx
index 69ad3de457..ecfbbf2162 100644
--- a/packages/docs/components/TableOfContents/paths.tsx
+++ b/packages/docs/components/TableOfContents/paths.tsx
@@ -45,6 +45,10 @@ export const TableOfContents: React.FC = () => {
<strong>warpPath()</strong>
<div>Remap the coordinates of a path</div>
</TOCItem>
+ <TOCItem link="/docs/paths/scale-path">
+ <strong>scalePath()</strong>
+ <div>Grow or shrink the size of the path</div>
+ </TOCItem>
<TOCItem link="/docs/paths/get-bounding-box">
<strong>getBoundingBox()</strong>
<div>Get the bounding box of a SVG path</div>
diff --git a/packages/docs/docs/paths/scale-path.md b/packages/docs/docs/paths/scale-path.md
new file mode 100644
index 0000000000..6b577b501e
--- /dev/null
+++ b/packages/docs/docs/paths/scale-path.md
@@ -0,0 +1,42 @@
+---
+image: /generated/articles-docs-paths-scale-path.png
+title: scalePath()
+crumb: "@remotion/paths"
+---
+
+_Part of the [`@remotion/paths`](/docs/paths) package. Available from v3.3.43_
+
+Allows you to grow or shrink the size of a path.
+
+```tsx twoslash title="scale-path.ts"
+import { scalePath } from "@remotion/paths";
+
+const newPath = scalePath("M 0 0 L 100 100", 1, 2); // "M 0 0 L 100 200";
+```
+
+The origin of the transform is the top left corner of the path. To use a different origin, first use [`translatePath()`](/docs/paths/translate-path) to move the path to the desired origin, then scale it, and finally move it back to the original origin.
+
+## Arguments
+
+### `path`
+
+_string_
+
+A valid SVG Path string.
+
+### `xScale`
+
+_number_
+
+The factor of which to scale the path horizontally. `1` will leave the path unchanged.
+
+### `yScale`
+
+_number_
+
+The factor of which to scale the path vertically. `1` will leave the path unchanged.
+
+## See also
+
+- [`@remotion/paths`](/docs/paths)
+- [Source code for this function](https://github.com/remotion-dev/remotion/blob/main/packages/paths/src/scale-path.ts)
diff --git a/packages/docs/sidebars.js b/packages/docs/sidebars.js
index 69b966581b..9c6225a7c4 100644
--- a/packages/docs/sidebars.js
+++ b/packages/docs/sidebars.js
@@ -263,6 +263,7 @@ module.exports = {
"paths/get-subpaths",
"paths/translate-path",
"paths/warp-path",
+ "paths/scale-path",
"paths/get-bounding-box",
"paths/extend-viewbox",
"paths/parse-path",
diff --git a/packages/docs/src/data/articles.ts b/packages/docs/src/data/articles.ts
index 6f76df6483..349c3b83c2 100644
--- a/packages/docs/src/data/articles.ts
+++ b/packages/docs/src/data/articles.ts
@@ -1289,6 +1289,13 @@ export const articles = [
compId: "articles-docs-paths-reverse-path",
crumb: "@remotion/paths",
},
+ {
+ id: "paths/scale-path",
+ title: "scalePath()",
+ relativePath: "docs/paths/scale-path.md",
+ compId: "articles-docs-paths-scale-path",
+ crumb: "@remotion/paths",
+ },
{
id: "paths/serialize-instructions",
title: "serializeInstructions()",
diff --git a/packages/docs/static/generated/articles-docs-paths-scale-path.png b/packages/docs/static/generated/articles-docs-paths-scale-path.png
new file mode 100644
index 0000000000..00b65cb165
Binary files /dev/null and b/packages/docs/static/generated/articles-docs-paths-scale-path.png differ
diff --git a/packages/paths/src/test/scale-path.test.ts b/packages/paths/src/test/scale-path.test.ts
new file mode 100644
index 0000000000..f0c07a568c
--- /dev/null
+++ b/packages/paths/src/test/scale-path.test.ts
@@ -0,0 +1,6 @@
+import {expect, test} from 'vitest';
+import {scalePath} from '../scale-path';
+
+test('scalePath() should work', () => {
+ expect(scalePath('M -10 -10 L 10 10', 2, 3)).toBe('M -10 -10 L 30 50');
+});