Skip to content

Commit

Permalink
Fix image height content fit (#9116)
Browse files Browse the repository at this point in the history
* fix image height content fit

* add changeset

* use `scale-down` instead of `contain`

* add changeset

* fix spacing

* apply image uploader styling to image preview

* Fix image/shared/ImagePreview style

* Fix

* Remove unnecessary styles from .image-frame

* Revert prev for the fullscreen mode

* Add stories

* fix python test

* move story files, fix python tests

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
Co-authored-by: Yuichiro Tachibana (Tsuchiya) <t.yic.yt@gmail.com>
  • Loading branch information
3 people authored Aug 21, 2024
1 parent 4375f2e commit ba6322e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 11 deletions.
8 changes: 8 additions & 0 deletions .changeset/poor-days-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@gradio/image": patch
"@gradio/simpleimage": patch
"@gradio/storybook": patch
"gradio": patch
---

fix:Fix image height content fit
37 changes: 37 additions & 0 deletions js/image/Image.stories.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import StaticImage from "./Index.svelte";
import { userEvent, within } from "@storybook/test";
import { allModes } from "../storybook/modes";
import image_file_100x100 from "../storybook/test_files/image_100x100.webp";
import image_file_100x1000 from "../storybook/test_files/image_100x100.webp";
export const meta = {
title: "Components/Image",
Expand Down Expand Up @@ -64,6 +66,41 @@
}}
/>

<Story
name="static with a vertically long image"
args={{
value: {
path: image_file_100x1000,
url: image_file_100x1000,
orig_name: "image.webp"
}
}}
/>

<Story
name="static with a vertically long image and a fixed height"
args={{
value: {
path: image_file_100x1000,
url: image_file_100x1000,
orig_name: "image.webp"
},
height: "500px"
}}
/>

<Story
name="static with a small image and a fixed height"
args={{
value: {
path: image_file_100x100,
url: image_file_100x100,
orig_name: "image.webp"
},
height: "500px"
}}
/>

<Story
name="interactive with upload, clipboard, and webcam"
args={{
Expand Down
23 changes: 17 additions & 6 deletions js/image/shared/ImagePreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
{/if}
</div>
<button on:click={handle_click}>
<div class:selectable>
<div class:selectable class="image-frame">
<Image src={value.url} alt="" loading="lazy" on:load />
</div>
</button>
Expand All @@ -111,19 +111,30 @@
height: 100%;
position: relative;
}
.image-container :global(img),
button {
.image-container button {
width: var(--size-full);
height: var(--size-full);
object-fit: contain;
display: block;
border-radius: var(--radius-lg);
display: flex;
align-items: center;
justify-content: center;
}
.image-frame {
width: auto;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
}
.image-frame :global(img) {
width: var(--size-full);
height: var(--size-full);
object-fit: scale-down;
}
.selectable {
cursor: crosshair;
}
Expand Down Expand Up @@ -152,6 +163,6 @@
:global(.image-container:fullscreen img) {
max-width: 90vw;
max-height: 90vh;
object-fit: contain;
object-fit: scale-down;
}
</style>
13 changes: 10 additions & 3 deletions js/image/shared/ImageUploader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@
}}
/>
{/if}
<div class="upload-container" class:reduced-height={sources.length > 1}>
<div
class="upload-container"
class:reduced-height={sources.length > 1}
style:width={value ? "auto" : "100%"}
>
<Upload
hidden={value !== null || active_source === "webcam"}
bind:this={upload_input}
Expand Down Expand Up @@ -165,7 +169,7 @@
.image-frame :global(img) {
width: var(--size-full);
height: var(--size-full);
object-fit: contain;
object-fit: scale-down;
}
.image-frame {
Expand All @@ -175,10 +179,13 @@
}
.upload-container {
display: flex;
align-items: center;
justify-content: center;
height: 100%;
flex-shrink: 1;
max-height: 100%;
width: 100%;
}
.reduced-height {
Expand Down
2 changes: 1 addition & 1 deletion js/simpleimage/shared/ImagePreview.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
button {
width: var(--size-full);
height: var(--size-full);
object-fit: contain;
object-fit: scale-down;
display: block;
border-radius: var(--radius-lg);
}
Expand Down
2 changes: 1 addition & 1 deletion js/simpleimage/shared/ImageUploader.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
.image-frame :global(img) {
width: var(--size-full);
height: var(--size-full);
object-fit: contain;
object-fit: scale-down;
}
.image-frame {
Expand Down
Binary file added js/storybook/test_files/image_100x100.webp
Binary file not shown.
Binary file added js/storybook/test_files/image_100x1000.webp
Binary file not shown.

0 comments on commit ba6322e

Please sign in to comment.