dramp77's picture
init
b64541c
raw
history blame
1.61 kB
import gradio as gr
import numpy as np
import PIL
from PIL import Image
size_options ={"1200 x 1500": (1200, 1500),
"1200 x 1200": (1200, 1200),
"1200 x 628": (1200, 628),
"Meta - Square (Feed)": (1200, 1200),
"Meta - Story": (1080, 1920),
"Tiktok Pangle - 1280 x 720": (1280, 720),
"Tiktok Pangle - 1200 x 628": (1200, 628),
"Tiktok Pangle - 640 x 640": (640, 640),
"Tiktok Pangle - 300 x 250": (300, 250),
"Tiktok Pangle - 720 x 1280": (720, 1280),
"Tiktok Pangle - 300 x 50": (300, 50),
"Tiktok Pangle - 320 x 50": (320, 50),
"Tiktok Pangle - 320 x 480": (320, 480),
"Tiktok Pangle - 250 x 250": (250, 250),
"Tiktok Pangle - 600 x 770": (600, 770),
"Tiktok Pangle - 720 x 1067": (720, 1067),
"Tiktok Pangle - 480 x 320": (480, 320)}
def change_size(image, size):
new_size = size_options[size]
image = image.resize(new_size, PIL.Image.Resampling.LANCZOS) # def change size
return image
def gradio_interface():# this is for gradio interface
with gr.Blocks() as demo:
gr.Markdown("# Image Resizer with Predefined Sizes")
with gr.Row():
image_input = gr.Image(type="pil", label="Upload Image")
size_input = gr.Dropdown(list(size_options.keys()), label="Select Size")
image_output = gr.Image(type="pil", label="Resized Image")
submit_button = gr.Button("Resize Image")
submit_button.click(fn=change_size, inputs=[image_input, size_input], outputs=image_output)
return demo
demo = gradio_interface()
demo.launch()