Skip to content

Commit

Permalink
Lazy load all images (#5528)
Browse files Browse the repository at this point in the history
* changes

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
  • Loading branch information
aliabid94 and gradio-pr-bot committed Sep 13, 2023
1 parent c5fe8eb commit dc86e4a
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/fruity-ducks-stay.md
@@ -0,0 +1,7 @@
---
"@gradio/gallery": minor
"@gradio/image": minor
"gradio": minor
---

feat:Lazy load all images
3 changes: 3 additions & 0 deletions js/gallery/static/Gallery.svelte
Expand Up @@ -207,6 +207,7 @@
style="height: calc(100% - {_value[selected_image][1]
? '80px'
: '60px'})"
loading="lazy"
/>
{#if _value[selected_image][1]}
<div class="caption">
Expand All @@ -229,6 +230,7 @@
src={image[0].data}
title={image[1] || null}
alt={image[1] || null}
loading="lazy"
/>
</button>
{/each}
Expand Down Expand Up @@ -265,6 +267,7 @@
<img
alt={caption || ""}
src={typeof image === "string" ? image : image.data}
loading="lazy"
/>
{#if caption}
<div class="caption-label">
Expand Down
6 changes: 6 additions & 0 deletions js/image/interactive/Image.svelte
Expand Up @@ -224,6 +224,7 @@
class:scale-x-[-1]={source === "webcam" && mirror_webcam}
class:selectable
on:click={handle_click}
loading="lazy"
/>
{:else if (tool === "sketch" || tool === "color-sketch") && (value !== null || static_image)}
{#key static_image}
Expand All @@ -234,6 +235,7 @@
alt=""
on:load={handle_image_load}
class:webcam={source === "webcam" && mirror_webcam}
loading="lazy"
/>
{/key}
{#if img_width > 0}
Expand Down Expand Up @@ -279,6 +281,7 @@
class:webcam={source === "webcam" && mirror_webcam}
class:selectable
on:click={handle_click}
loading="lazy"
/>
{/if}
</Upload>
Expand Down Expand Up @@ -341,6 +344,7 @@
class:selectable
class:webcam={source === "webcam" && mirror_webcam}
on:click={handle_click}
loading="lazy"
/>
{:else if (tool === "sketch" || tool === "color-sketch") && (value !== null || static_image)}
{#key static_image}
Expand All @@ -351,6 +355,7 @@
alt=""
on:load={handle_image_load}
class:webcam={source === "webcam" && mirror_webcam}
loading="lazy"
/>
{/key}
{#if img_width > 0}
Expand Down Expand Up @@ -393,6 +398,7 @@
class:webcam={source === "webcam" && mirror_webcam}
class:selectable
on:click={handle_click}
loading="lazy"
/>
{/if}
</div>
Expand Down
8 changes: 7 additions & 1 deletion js/image/static/ImagePreview.svelte
Expand Up @@ -61,7 +61,13 @@
<!-- TODO: fix -->
<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-noninteractive-element-interactions-->
<img src={value} alt="" class:selectable on:click={handle_click} />
<img
src={value}
alt=""
class:selectable
on:click={handle_click}
loading="lazy"
/>
{/if}

<style>
Expand Down

0 comments on commit dc86e4a

Please sign in to comment.