Send subtitle frame placement metadata from server to client
Tim Falken authored 6 months ago
Previously, the server rendered image subtitles but threw away all positioning
metadata, sending only the PNG buffer. The client had no way to know the
actual frame dimensions or position within the rendered canvas, so it relied
on CSS max-height constraints (which didn't scale properly for downscaled frames).
Now the server:
1. Preserves positioning metadata (left, top, width, height, canvasWidth, canvasHeight)
2. Returns frame data as an object with both the PNG buffer and metadata
3. Sends headers with the placement information
The client:
1. Reads X-Subtitle-Frame-* headers from the response
2. Calculates percentage-based positioning: (frameLeft / canvasWidth) * 100%
3. Calculates percentage-based sizing: (frameWidth / canvasWidth) * 100%
4. Applies these values to properly position and scale the image
This allows downscaled subtitle frames (rendered at 0.5 scale) to:
- Display at correct size relative to the canvas they were rendered for
- Scale properly in both normal and fullscreen modes
- Maintain proper aspect ratio and positioning
Fixes the subtitle display issue where downscaled frames appeared too small
and fell off screen edges in fullscreen mode.