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.
Installation agent prête
Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.
npx -y tokrepo@latest install 7c51fb5b-4260-455e-9f73-3d0b11015d99 --target codexÀ exécuter après confirmation du plan en dry-run.
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.
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.
How to use
- Include this skill rule in your Remotion agent configuration
- When composing text-heavy scenes, the agent references the rule to pick the right measurement API
- Use
measureText()from the canvas 2D context or Remotion's layout utilities to get bounding box dimensions - Apply conditional font sizing or truncation based on measured width vs container width
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`;
}
Related on TokRepo
- Coding tools -- AI-powered coding and video development
- Design tools -- Visual design and layout tooling
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
Questions fréquentes
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.
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.
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.
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.
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.
Sources citées (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
En lien sur TokRepo
Source et remerciements
Created by Remotion. Licensed under MIT. remotion-dev/skills — Rule:
measuring-text
Part of the Remotion AI Skill collection on TokRepo.
Fil de discussion
Actifs similaires
Remotion Rule: Text Animations
Remotion skill rule: Typography and text animation patterns for Remotion.. Part of the official Remotion Agent Skill for programmatic video in React.
Remotion Rule: Get Video Dimensions
Remotion skill rule: Getting the width and height of a video file with Mediabunny. Part of the official Remotion Agent Skill for programmatic video in React.
Remotion Rule: Videos
Remotion skill rule: Embedding videos in Remotion - trimming, volume, speed, looping, pitch. Part of the official Remotion Agent Skill for programmatic video in React.
Remotion Rule: Timing
Remotion skill rule: Interpolation curves in Remotion - linear, easing, spring animations. Part of the official Remotion Agent Skill for programmatic video in React.