Skip to content

Commit

Permalink
fix(web): use native image decoder (#3074)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
Co-authored-by: Alex Tran <alex.tran1502@gmail.com>
  • Loading branch information
3 people authored Nov 29, 2023
1 parent e5d083f commit 6969002
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<section class="flex flex-wrap gap-14 overflow-y-auto px-20">
<!-- Image grid -->
<div class="flex flex-wrap gap-[2px]">
{#each album.assets as asset}
{#each album.assets as asset (asset.id)}
<Thumbnail {asset} on:click={() => (selectedThumbnail = asset)} selected={isSelected(asset.id)} />
{/each}
</div>
Expand Down
14 changes: 10 additions & 4 deletions web/src/lib/components/assets/thumbnail/image-thumbnail.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { imageLoad } from '$lib/utils/image-load';
import { onMount, tick } from 'svelte';
import { fade } from 'svelte/transition';
import { thumbHashToDataURL } from 'thumbhash';
import { Buffer } from 'buffer';
Expand All @@ -18,12 +18,20 @@
export let hidden = false;
export let border = false;
export let preload = true;
export let eyeColor: 'black' | 'white' = 'white';
let complete = false;
let img: HTMLImageElement;
export let eyeColor: 'black' | 'white' = 'white';
onMount(async () => {
await img.decode();
await tick();
complete = true;
});
</script>

<img
bind:this={img}
loading={preload ? 'eager' : 'lazy'}
style:width={widthStyle}
style:height={heightStyle}
Expand All @@ -40,8 +48,6 @@
class:rounded-full={circle}
class:opacity-0={!thumbhash && !complete}
draggable="false"
use:imageLoad
on:image-load|once={() => (complete = true)}
/>

{#if hidden}
Expand Down
16 changes: 13 additions & 3 deletions web/src/lib/components/shared-components/user-avatar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</script>

<script lang="ts">
import { imageLoad } from '$lib/utils/image-load';
import { onMount, tick } from 'svelte';
import { UserAvatarColor, api } from '@api';
interface User {
Expand All @@ -22,8 +22,19 @@
export let showTitle = true;
export let showProfileImage = true;
let img: HTMLImageElement;
let showFallback = true;
onMount(async () => {
if (!user.profileImagePath) {
return;
}
await img.decode();
await tick();
showFallback = false;
});
const colorClasses: Record<UserAvatarColor, string> = {
primary: 'bg-immich-primary dark:bg-immich-dark-primary text-immich-dark-fg dark:text-immich-fg',
pink: 'bg-pink-400 text-immich-bg',
Expand Down Expand Up @@ -62,13 +73,12 @@
>
{#if showProfileImage && user.profileImagePath}
<img
bind:this={img}
src={api.getProfileImageUrl(user.id)}
alt="Profile image of {title}"
class="h-full w-full object-cover"
class:hidden={showFallback}
draggable="false"
use:imageLoad
on:image-load={() => (showFallback = false)}
/>
{/if}
{#if showFallback}
Expand Down
38 changes: 0 additions & 38 deletions web/src/lib/utils/image-load.ts

This file was deleted.

2 changes: 1 addition & 1 deletion web/src/routes/(user)/explore/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<p class="mb-4 font-medium dark:text-immich-dark-fg">Places</p>
</div>
<div class="flex flex-row flex-wrap gap-4">
{#each places as item}
{#each places as item (item.data.id)}
<a class="relative" href="/search?{Field.CITY}={item.value}" draggable="false">
<div
class="flex w-[calc((100vw-(72px+5rem))/2)] max-w-[156px] justify-center overflow-hidden rounded-xl brightness-75 filter"
Expand Down

0 comments on commit 6969002

Please sign in to comment.