diff options
| author | Maze Winther <mazewinther@gmail.com> | 2025-08-31 14:35:24 +0200 |
|---|---|---|
| committer | Maze Winther <mazewinther@gmail.com> | 2025-08-31 14:35:24 +0200 |
| commit | 73a156c002b9f97b133d89b1e07f11eec7641576 (patch) | |
| tree | 85cf226a2a1ff164de077604296dfaf2be28071e /apps/web/src/lib/timeline-renderer.ts | |
| parent | 29fdd8568dbb9c67ee19492781f3f03eb2c3bd24 (diff) | |
| download | opencut-73a156c002b9f97b133d89b1e07f11eec7641576.tar.gz | |
gradient backgrounds now work
Diffstat (limited to 'apps/web/src/lib/timeline-renderer.ts')
| -rw-r--r-- | apps/web/src/lib/timeline-renderer.ts | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/apps/web/src/lib/timeline-renderer.ts b/apps/web/src/lib/timeline-renderer.ts index ddc361b5..4d00129c 100644 --- a/apps/web/src/lib/timeline-renderer.ts +++ b/apps/web/src/lib/timeline-renderer.ts @@ -2,6 +2,7 @@ import type { TimelineTrack } from "@/types/timeline"; import type { MediaFile } from "@/types/media"; import type { BlurIntensity } from "@/types/project"; import { videoCache } from "./video-cache"; +import { drawCssBackground } from "./canvas-gradients"; export interface RenderContext { ctx: CanvasRenderingContext2D; @@ -48,11 +49,24 @@ export async function renderTimelineFrame({ }: RenderContext): Promise<void> { // Background ctx.clearRect(0, 0, canvasWidth, canvasHeight); - if (backgroundColor && backgroundColor !== "transparent") { + if ( + backgroundColor && + backgroundColor !== "transparent" && + !backgroundColor.includes("gradient") + ) { ctx.fillStyle = backgroundColor; ctx.fillRect(0, 0, canvasWidth, canvasHeight); } + // If backgroundColor is a CSS gradient string, draw it using JS (no foreignObject) to avoid CORS tainting + if (backgroundColor && backgroundColor.includes("gradient")) { + try { + drawCssBackground(ctx, canvasWidth, canvasHeight, backgroundColor); + } catch { + // best-effort; ignore failures + } + } + const scaleX = projectCanvasSize ? canvasWidth / projectCanvasSize.width : 1; const scaleY = projectCanvasSize ? canvasHeight / projectCanvasSize.height |
