0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Rendering kinetic typography to APNG and transparent WebM in the browser

0
Posted at

I wanted a short line of type to enter, hold, and leave, then to sit over a video or a slide without a black box around it. The usual path is a desktop timeline and a ProRes or MOV with an alpha channel. I wanted the same result from a canvas loop in the browser: typography I could type, time, and export as a looping GIF, an APNG, or a transparent WebM, without uploading the frames to a server.

This post is about that export path. I am Ethan Brooks, and AnimatePilot is my own product, launched in 2026. The text tool on my site is built this way. I will point to it once, at the end. The notes below should work without it.

A canvas loop is a clock, not a timeline

I treat the animation as a function of time. On each frame I clear the canvas, compute a phase from performance.now() or from a fixed frame index, draw the glyphs, and then decide whether to store that frame. For a 12-frame-per-second loop of two seconds I want 24 frames, not whatever the display happened to refresh.

const fps = 12;
const duration = 2;
const frames = fps * duration;
const canvas = document.querySelector('canvas');
const ctx = canvas.getContext('2d', { alpha: true });

for (let i = 0; i < frames; i++) {
  const t = i / fps; // seconds
  ctx.clearRect(0, 0, canvas.width, canvas.height);
  drawType(ctx, t, duration);
  await collectFrame(canvas, i);
}

clearRect on an alpha canvas must actually clear to transparent, not to a default white fill. If you fill with '#00000000' or use clearRect on a 2D context created with { alpha: true }, you can keep the background empty. If you forget and fill with black, every later format will carry a matte.

Timing and easing belong in the draw function

Kinetic type is mostly about when a letter arrives, not about a particular filter. I keep a small table: delay per character, a duration, and an easing function. A letter that has not started yet is not drawn. A letter that has finished stays on its final transform until the exit begins. Drawing “all the text, then animating the group” looks cheaper and also looks like a single block sliding in, which is usually not what I want.

For exit, I prefer a hold in the middle of the loop so the line can be read. A two-second loop might spend a second at rest. If every frame is a move, the export feels restless and the file is larger for no reason.

Alpha in APNG and in WebM

PNG frames already understand alpha. An APNG is a sequence of those frames with timing. When I build one in the browser I either use a small encoder that accepts raw RGBA, or I assemble PNG frames and pack them. The important part is not the packer. It is that the canvas really had transparent pixels, and that I did not premultiply twice.

Transparent WebM is stricter. VP9 with alpha (or VP8 plus an alpha plane, depending on the encoder) is not something every browser encoder exposes in the same way. In practice I use a wasm encoder when I need a WebM with a real alpha channel, and I test the file over a coloured background, not over black. Black hides a matte. A green or mid-grey reveals it immediately.

A GIF can also be “transparent,” but only in the sense of a single colour index marked as empty. Hairline antialiasing around a letter will fringe if the matte colour was wrong. For type, I often prefer APNG or WebM and keep the GIF as a fallback with a carefully chosen matte.

Frame disposal and palettes

If you go to GIF at all, watch disposal. A letter that moves away must not leave a ghost of itself. I start with clearing the frame (disposal that restores to background) rather than stacking diffs, unless I have measured that the diffs are clean. For APNG, I am similarly conservative: full frames with alpha, not a clever subtraction that will break in one of the viewers.

One implementation note, then a link

The rest of my page is product surface: twelve style presets, export buttons, no watermark, nothing uploaded. One of those presets is still marked as coming soon; the others run in the tab. The rendering path is the one above. The public page for the tool I built is https://animatepilot.com/animated-text-maker. If you already have your own canvas loop, you do not need it. If you want a page that already does the typography and the exports, that is the one I keep.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?