Skip to content

High performance self-hosted photo and video management solution.

fix: OCR bounding box positioning (#28568)

Brandon Wees2dd6b47714a1
diff --git a/web/src/lib/components/AdaptiveImage.svelte b/web/src/lib/components/AdaptiveImage.svelte
index 4f3522887c..04136c721c 100644
--- a/web/src/lib/components/AdaptiveImage.svelte
+++ b/web/src/lib/components/AdaptiveImage.svelte
@@ -149,29 +149,35 @@
return { width: 1, height: 1 };
});
- const { insetInlineStart, top, rasterWidth, rasterHeight, rasterScale } = $derived.by(() => {
- const scaleFn = objectFit === 'cover' ? scaleToCover : scaleToFit;
- const { width, height } = scaleFn(imageDimensions, container);
- if (maxRasterPixels === 0) {
+ const { insetInlineStart, top, displayWidth, displayHeight, rasterWidth, rasterHeight, rasterScale } = $derived.by(
+ () => {
+ const scaleFn = objectFit === 'cover' ? scaleToCover : scaleToFit;
+ const { width, height } = scaleFn(imageDimensions, container);
+ if (maxRasterPixels === 0) {
+ return {
+ insetInlineStart: (container.width - width) / 2 + 'px',
+ top: (container.height - height) / 2 + 'px',
+ displayWidth: width + 'px',
+ displayHeight: height + 'px',
+ rasterWidth: width + 'px',
+ rasterHeight: height + 'px',
+ rasterScale: 1,
+ };
+ }
+ const nativeRatio = imageDimensions.width / width;
+ const budgetRatio = Math.sqrt(maxRasterPixels / Math.max(width * height, 1));
+ const rasterRatio = Math.max(1, Math.min(nativeRatio, budgetRatio));
return {
insetInlineStart: (container.width - width) / 2 + 'px',
top: (container.height - height) / 2 + 'px',
- rasterWidth: width + 'px',
- rasterHeight: height + 'px',
- rasterScale: 1,
+ displayWidth: width + 'px',
+ displayHeight: height + 'px',
+ rasterWidth: width * rasterRatio + 'px',
+ rasterHeight: height * rasterRatio + 'px',
+ rasterScale: 1 / rasterRatio,
};
- }
- const nativeRatio = imageDimensions.width / width;
- const budgetRatio = Math.sqrt(maxRasterPixels / Math.max(width * height, 1));
- const rasterRatio = Math.max(1, Math.min(nativeRatio, budgetRatio));
- return {
- insetInlineStart: (container.width - width) / 2 + 'px',
- top: (container.height - height) / 2 + 'px',
- rasterWidth: width * rasterRatio + 'px',
- rasterHeight: height * rasterRatio + 'px',
- rasterScale: 1 / rasterRatio,
- };
- });
+ },
+ );
const { status } = $derived(adaptiveImageLoader);
const alt = $derived(status.urls.preview ? $getAltText(toTimelineAsset(asset)) : '');
@@ -216,69 +222,78 @@
{@render backdrop?.()}
<div
- class="pointer-events-none absolute"
+ class="pointer-events-none absolute overflow-hidden"
style:inset-inline-start={insetInlineStart}
style:top
- style:width={rasterWidth}
- style:height={rasterHeight}
- style:transform="scale({rasterScale})"
- style:transform-origin="0 0"
- style:will-change={maxRasterPixels > 0 ? 'transform' : undefined}
+ style:width={displayWidth}
+ style:height={displayHeight}
>
- {#if show.alphaBackground}
- <AlphaBackground />
- {/if}
+ <div
+ style:width={rasterWidth}
+ style:height={rasterHeight}
+ style:transform="scale({rasterScale})"
+ style:transform-origin="0 0"
+ style:will-change={maxRasterPixels > 0 ? 'transform' : undefined}
+ >
+ {#if show.alphaBackground}
+ <AlphaBackground />
+ {/if}
- {#if show.thumbhash}
- {#if asset.thumbhash}
- <!-- Thumbhash / spinner layer -->
- <Thumbhash base64ThumbHash={asset.thumbhash} class="absolute size-full" />
- {:else if show.spinner}
- <DelayedLoadingSpinner />
+ {#if show.thumbhash}
+ {#if asset.thumbhash}
+ <!-- Thumbhash / spinner layer -->
+ <Thumbhash base64ThumbHash={asset.thumbhash} class="absolute size-full" />
+ {:else if show.spinner}
+ <DelayedLoadingSpinner />
+ {/if}
{/if}
- {/if}
- {#if show.thumbnail}
- <ImageLayer
- {adaptiveImageLoader}
- width={rasterWidth}
- height={rasterHeight}
- quality="thumbnail"
- src={status.urls.thumbnail}
- alt=""
- role="presentation"
- bind:ref={thumbnailElement}
- />
- {/if}
+ {#if show.thumbnail}
+ <ImageLayer
+ {adaptiveImageLoader}
+ width={rasterWidth}
+ height={rasterHeight}
+ quality="thumbnail"
+ src={status.urls.thumbnail}
+ alt=""
+ role="presentation"
+ bind:ref={thumbnailElement}
+ />
+ {/if}
- {#if show.brokenAsset}
- <BrokenAsset class="absolute size-full text-xl" />
- {/if}
+ {#if show.brokenAsset}
+ <BrokenAsset class="absolute size-full text-xl" />
+ {/if}
- {#if show.preview}
- <ImageLayer
- {adaptiveImageLoader}
- {alt}
- width={rasterWidth}
- height={rasterHeight}
- {overlays}
- quality="preview"
- src={status.urls.preview}
- bind:ref={previewElement}
- />
- {/if}
+ {#if show.preview}
+ <ImageLayer
+ {adaptiveImageLoader}
+ {alt}
+ width={rasterWidth}
+ height={rasterHeight}
+ quality="preview"
+ src={status.urls.preview}
+ bind:ref={previewElement}
+ />
+ {/if}
+
+ {#if show.original}
+ <ImageLayer
+ {adaptiveImageLoader}
+ {alt}
+ width={rasterWidth}
+ height={rasterHeight}
+ quality="original"
+ src={status.urls.original}
+ bind:ref={originalElement}
+ />
+ {/if}
+ </div>
- {#if show.original}
- <ImageLayer
- {adaptiveImageLoader}
- {alt}
- width={rasterWidth}
- height={rasterHeight}
- {overlays}
- quality="original"
- src={status.urls.original}
- bind:ref={originalElement}
- />
+ {#if overlays}
+ <div class="pointer-events-none absolute inset-0">
+ {@render overlays()}
+ </div>
{/if}
</div>
</div>
diff --git a/web/src/lib/components/ImageLayer.svelte b/web/src/lib/components/ImageLayer.svelte
index 1ac854259d..40bf7d6965 100644
--- a/web/src/lib/components/ImageLayer.svelte
+++ b/web/src/lib/components/ImageLayer.svelte
@@ -1,7 +1,6 @@
<script lang="ts">
import Image from '$lib/components/Image.svelte';
import type { AdaptiveImageLoader, ImageQuality } from '$lib/utils/adaptive-image-loader.svelte';
- import type { Snippet } from 'svelte';
type Props = {
adaptiveImageLoader: AdaptiveImageLoader;
@@ -12,20 +11,9 @@
ref?: HTMLImageElement;
width: string;
height: string;
- overlays?: Snippet;
};
- let {
- adaptiveImageLoader,
- quality,
- src,
- alt = '',
- role,
- ref = $bindable(),
- width,
- height,
- overlays,
- }: Props = $props();
+ let { adaptiveImageLoader, quality, src, alt = '', role, ref = $bindable(), width, height }: Props = $props();
</script>
{#key adaptiveImageLoader}
@@ -42,6 +30,5 @@
draggable={false}
data-testid={quality}
/>
- {@render overlays?.()}
</div>
{/key}