We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gradio==5.4.0
I want to auto resize / crop user uploaded image and replace processed image inside in gr.ImageEditor
Here the code I use
So after image edited the image editing features disappears
Here what I mean
imgs = gr.ImageEditor(sources='upload', type="pil", label='Human. Mask with pen or use auto-masking', interactive=True) def process_editor_image(image_dict, enable_processing): if not enable_processing or image_dict is None: return image_dict if isinstance(image_dict, dict) and 'background' in image_dict: image_dict['background'] = process_image_to_768x1024(image_dict['background']) return image_dict def process_single_image(image, enable_processing): if not enable_processing or image is None: return image return process_image_to_768x1024(image) # Add image processing event handlers imgs.upload( fn=process_editor_image, inputs=[imgs, auto_process], outputs=imgs, ) def process_image_to_768x1024(img): if not isinstance(img, Image.Image): return img # Create a new white background image target_width, target_height = 768, 1024 new_img = Image.new('RGB', (target_width, target_height), 'white') # Calculate aspect ratios aspect_ratio = img.width / img.height target_aspect = target_width / target_height if aspect_ratio > target_aspect: # Image is wider than target new_width = target_width new_height = int(target_width / aspect_ratio) resize_img = img.resize((new_width, new_height), Image.Resampling.LANCZOS) paste_y = (target_height - new_height) // 2 new_img.paste(resize_img, (0, paste_y)) else: # Image is taller than target new_height = target_height new_width = int(target_height * aspect_ratio) resize_img = img.resize((new_width, new_height), Image.Resampling.LANCZOS) paste_x = (target_width - new_width) // 2 new_img.paste(resize_img, (paste_x, 0)) return new_img def process_uploaded_image(img, enable_processing): if not enable_processing or img is None: return img if isinstance(img, dict): # For ImageEditor if img.get('background'): img['background'] = process_image_to_768x1024(img['background']) return img return process_image_to_768x1024(img)
The text was updated successfully, but these errors were encountered:
I believe this is the same underlying issue as #9694, cc @hannahblair
Sorry, something went wrong.
freddyaboulton
Successfully merging a pull request may close this issue.
Describe the bug
gradio==5.4.0
I want to auto resize / crop user uploaded image and replace processed image inside in gr.ImageEditor
Here the code I use
So after image edited the image editing features disappears
Here what I mean
The text was updated successfully, but these errors were encountered: