Esta página se muestra en inglés. Una traducción al español está en curso.
SkillsMar 29, 2026·1 min de lectura

Remotion Rule: Measuring Text

Remotion skill rule: Measuring text dimensions, fitting text to containers, and checking overflow. Part of the official Remotion Agent Skill for programmatic video in React.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
Remotion Rule: Measuring Text
Comando de instalación directa
npx -y tokrepo@latest install 7c51fb5b-4260-455e-9f73-3d0b11015d99 --target codex

Ejecutar después de confirmar el plan con dry-run.

TL;DR
Measure text width and height in Remotion to fit text into containers and detect overflow.
§01

What it is

This is a Remotion skill rule that covers measuring text dimensions, fitting text to containers, and checking for overflow. It is part of the official Remotion Agent Skill for programmatic video creation in React.

Developers and AI agents building Remotion videos need precise text measurement to avoid clipping, overflow, or misaligned layouts. This rule provides the patterns and API calls to handle those cases.

§02

How it saves time or tokens

Text measurement in HTML canvas or SVG requires boilerplate: creating off-screen elements, computing bounding boxes, handling font loading. This skill rule gives agents a ready-made pattern so they produce correct text-fitting code on the first attempt, saving token_estimate of approximately 500 tokens per invocation.

Instead of trial-and-error rendering, the agent applies the rule and generates a working composition without visual debugging.

§03

How to use

  1. Include this skill rule in your Remotion agent configuration
  2. When composing text-heavy scenes, the agent references the rule to pick the right measurement API
  3. Use measureText() from the canvas 2D context or Remotion's layout utilities to get bounding box dimensions
  4. Apply conditional font sizing or truncation based on measured width vs container width
§04

Example

const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
ctx.font = '48px Inter';
const metrics = ctx.measureText('Hello Remotion');
const textWidth = metrics.width;
const textHeight = metrics.actualBoundingBoxAscent + metrics.actualBoundingBoxDescent;

if (textWidth > containerWidth) {
  // Reduce font size or truncate
  const scale = containerWidth / textWidth;
  ctx.font = `${Math.floor(48 * scale)}px Inter`;
}
§05

Related on TokRepo

§06

Common pitfalls

  • Measuring text before fonts are loaded returns incorrect widths; always wait for document.fonts.ready
  • Canvas measureText does not account for line-height or letter-spacing; add manual padding
  • Remotion renders frames server-side, so DOM-based measurement must happen during the render lifecycle, not in module scope

Preguntas frecuentes

Why not just use CSS to fit text?+

CSS auto-sizing works in browsers but Remotion renders frames programmatically. You need explicit pixel dimensions to ensure consistent output across all frames. Canvas measureText gives you those exact numbers before rendering.

Does this rule work with custom fonts?+

Yes, but you must ensure the font is loaded before measuring. Use the Font Face API or Remotion's font loading utilities to preload the font, then measure. Measuring before the font loads will fall back to a default font and produce wrong dimensions.

Can I measure multi-line text with this approach?+

Canvas measureText handles single lines. For multi-line text, split by newlines, measure each line individually, and sum the heights. Add line-height spacing between lines. Alternatively, use an off-screen DOM element with the same CSS for automatic wrapping measurement.

What is the performance cost of text measurement?+

Canvas measureText is fast, typically under 1 millisecond per call. It is safe to call per frame if needed. The DOM-based approach is slower due to layout reflow, so prefer canvas measurement for per-frame calculations.

How does this relate to the Remotion Agent Skill?+

The Remotion Agent Skill is a collection of rules that guide AI agents in building Remotion videos. This specific rule covers text measurement, one of the most common tasks. Other rules handle animation timing, composition structure, and asset loading.

Referencias (3)
  • Remotion GitHub— Remotion is a framework for creating videos programmatically using React
  • MDN Web Docs— Canvas measureText returns a TextMetrics object with width and bounding box info
  • MDN Web Docs— Font Face API enables programmatic font loading detection
🙏

Fuente y agradecimientos

Created by Remotion. Licensed under MIT. remotion-dev/skills — Rule: measuring-text

Part of the Remotion AI Skill collection on TokRepo.

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados