From ba6322ec2bb975f15389fe0700816bf671c6819d Mon Sep 17 00:00:00 2001 From: Hannah Date: Wed, 21 Aug 2024 19:41:40 +0200 Subject: [PATCH] Fix image height content fit (#9116) * 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 Co-authored-by: Yuichiro Tachibana (Tsuchiya) --- .changeset/poor-days-eat.md | 8 +++++ js/image/Image.stories.svelte | 37 ++++++++++++++++++++ js/image/shared/ImagePreview.svelte | 23 ++++++++---- js/image/shared/ImageUploader.svelte | 13 +++++-- js/simpleimage/shared/ImagePreview.svelte | 2 +- js/simpleimage/shared/ImageUploader.svelte | 2 +- js/storybook/test_files/image_100x100.webp | Bin 0 -> 318 bytes js/storybook/test_files/image_100x1000.webp | Bin 0 -> 790 bytes 8 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 .changeset/poor-days-eat.md create mode 100644 js/storybook/test_files/image_100x100.webp create mode 100644 js/storybook/test_files/image_100x1000.webp diff --git a/.changeset/poor-days-eat.md b/.changeset/poor-days-eat.md new file mode 100644 index 0000000000000..533b64d2e9530 --- /dev/null +++ b/.changeset/poor-days-eat.md @@ -0,0 +1,8 @@ +--- +"@gradio/image": patch +"@gradio/simpleimage": patch +"@gradio/storybook": patch +"gradio": patch +--- + +fix:Fix image height content fit diff --git a/js/image/Image.stories.svelte b/js/image/Image.stories.svelte index 9e26168498c2e..e4f0beb69ee1d 100644 --- a/js/image/Image.stories.svelte +++ b/js/image/Image.stories.svelte @@ -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", @@ -64,6 +66,41 @@ }} /> + + + + + + @@ -111,12 +111,10 @@ 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; @@ -124,6 +122,19 @@ 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; } @@ -152,6 +163,6 @@ :global(.image-container:fullscreen img) { max-width: 90vw; max-height: 90vh; - object-fit: contain; + object-fit: scale-down; } diff --git a/js/image/shared/ImageUploader.svelte b/js/image/shared/ImageUploader.svelte index 17317c621e01f..68f79961e4cb2 100644 --- a/js/image/shared/ImageUploader.svelte +++ b/js/image/shared/ImageUploader.svelte @@ -109,7 +109,11 @@ }} /> {/if} -
1}> +
1} + style:width={value ? "auto" : "100%"} + >