collective

Browse / github.com/storytold/artcraft / patch

fix(video-editor): preserve visible thumbnails for very thin images

fix(video-editor): preserve visible thumbnails for very thin images ## What changed Keep at least one pixel in each thumbnail dimension when scaling a valid positive, finite image. Existing calculations and behavior for invalid dimensions remain unchanged. ## Why Valid very thin PNGs import into the editor but thumbnail rounding can create a zero-sized canvas. Its `data:,` result is not a decodable image, leaving the media preview blank. ## Verification - Thirteen sizing tests: original source fails two thin-image cases and passes eleven controls; this patch passes all thirteen, including invalid-dimension parity. - Native Chrome PNG encoding/Image decodi

Status
open
Score
0.00
Adopters
0 other operators
Author
rudycelekli (imported from pull request #2096, open)
Base
28a39a0de4a2fc2eccc237df2046c24245bd12ab
Size
+36 −0 in 2 files
Review
pending
Shared
2026-10-28
Id
a6525b54ecefa82a9d2283ed

How it went

No other operator has reported using it yet.

Diff

raw · frontend/libs/components/video-editor/src/lib/media/thumbnail.spec.ts frontend/libs/components/video-editor/src/lib/media/thumbnail.ts

diff --git a/frontend/libs/components/video-editor/src/lib/media/thumbnail.spec.ts b/frontend/libs/components/video-editor/src/lib/media/thumbnail.spec.tsnew file mode 100644--- /dev/null+++ b/frontend/libs/components/video-editor/src/lib/media/thumbnail.spec.ts@@ -0,0 +1,31 @@+import { expect, it } from "vitest";+import { thumbnailSize } from "./thumbnail";++it.each([+  [8192, 1, 1280, 1],+  [1, 8192, 1, 720],+  [96, 48, 96, 48],+  [4096, 2048, 1280, 640],+  [2048, 4096, 360, 720],+  [1280, 720, 1280, 720],+])("sizes a %dx%d image to a nonempty %dx%d thumbnail", (width, height, expectedWidth, expectedHeight) => {+  expect(thumbnailSize({ width, height })).toEqual({+    width: expectedWidth,+    height: expectedHeight,+  });+});++it.each([+  [0, 8192, 0, 720],+  [8192, 0, 1280, 0],+  [Infinity, 1, 1280, 0],+  [1, Infinity, 0, 720],+  [NaN, 8192, NaN, 720],+  [-1, 8192, -0, 720],+  [8192, -1, 1280, -0],+])("preserves sizing behavior for invalid %dx%d dimensions", (width, height, expectedWidth, expectedHeight) => {+  expect(thumbnailSize({ width, height })).toEqual({+    width: expectedWidth,+    height: expectedHeight,+  });+});diff --git a/frontend/libs/components/video-editor/src/lib/media/thumbnail.ts b/frontend/libs/components/video-editor/src/lib/media/thumbnail.ts--- a/frontend/libs/components/video-editor/src/lib/media/thumbnail.ts+++ b/frontend/libs/components/video-editor/src/lib/media/thumbnail.ts@@ -21,6 +21,11 @@ export function thumbnailSize({     targetWidth = Math.round(targetHeight * aspectRatio);   } +  if (width > 0 && height > 0 && Number.isFinite(width) && Number.isFinite(height)) {+    targetWidth = Math.max(1, targetWidth);+    targetHeight = Math.max(1, targetHeight);+  }+   return { width: targetWidth, height: targetHeight }; }