MCPcopy Index your code
hub / github.com/ColmapView/Colmapview.github.io / canvasToBlobUrl

Function canvasToBlobUrl

src/hooks/useThumbnail.ts:15–33  ·  view source on GitHub ↗

* Process canvas to blob URL for thumbnails.

(canvas: HTMLCanvasElement | OffscreenCanvas)

Source from the content-addressed store, hash-verified

13 * Process canvas to blob URL for thumbnails.
14 */
15async function canvasToBlobUrl(canvas: HTMLCanvasElement | OffscreenCanvas): Promise<string | null> {
16 return new Promise((resolve) => {
17 if (isOffscreenCanvas(canvas)) {
18 canvas.convertToBlob({ type: 'image/jpeg', quality: 0.75 }).then((blob) => {
19 resolve(URL.createObjectURL(blob));
20 }).catch(() => {
21 resolve(null);
22 });
23 } else {
24 canvas.toBlob((blob) => {
25 if (blob) {
26 resolve(URL.createObjectURL(blob));
27 } else {
28 resolve(null);
29 }
30 }, 'image/jpeg', 0.75);
31 }
32 });
33}
34
35// Create the thumbnail cache instance
36const thumbnailCache = createImageCache<string>({

Callers

nothing calls this directly

Calls 4

isOffscreenCanvasFunction · 0.90
convertToBlobMethod · 0.80
toBlobMethod · 0.65
resolveFunction · 0.50

Tested by

no test coverage detected