pngwn / gradio-imageslider

ImageSlider custom component for gradio.
https://huggingface.co/spaces/pngwn/gradio_imageslider
31 stars 5 forks source link

add option to set image format in component #29

Open breengles opened 6 months ago

breengles commented 6 months ago

Currently, images saved from the ImageSlider component are in webp format. This PR adds option to override this by setting image_format property with default value matching previous webp format.

As a workaround, you can pre-save images in the desired format and send them to slider as filepaths:

silder = ImageSlider(..., type="filepath")

and then smth like that

from PIL import Image

def process(...):
    ...
    left_image: Image.Image
    right_image: Image.Image

    left_image_path = "some/path/to/left_image.png"
    right_image_path = "some/path/to/right_image.png"
    left_image.save(left_image_path)
    right_image.save(right_image_path)
    return (left_image_path, right_image_path)
deltheil commented 2 months ago

@pngwn what's your take on this? (would be useful IMHO)

ZhengPeng7 commented 2 months ago

It's very useful, and there've been some people asking me for this. Could the author add this option? Many thanks!@pngwn

breengles commented 2 months ago

FIY: if you need specific format in output you can pass in paths to images - then they will be available in slider in their respected extensions

ZhengPeng7 commented 2 months ago

Yeah, thanks. I know what you mean, and it can be done that way. However, it needs to change many existing codes, so I still hope the author can update this function.