From 57f8d4b133a3f397a95a1776ed25f48df75045e9 Mon Sep 17 00:00:00 2001 From: Ayrton Sparling Date: Sat, 25 Jul 2026 05:51:58 +0000 Subject: [PATCH] feat(images): add width/height parameters to generate_image and edit_image tools Allow specifying output image dimensions via optional width and height parameters on both built-in image generation and image editing tools. --- backend/open_webui/tools/builtin.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/backend/open_webui/tools/builtin.py b/backend/open_webui/tools/builtin.py index 1d1bf8572d..59d38f9650 100644 --- a/backend/open_webui/tools/builtin.py +++ b/backend/open_webui/tools/builtin.py @@ -350,6 +350,8 @@ async def fetch_url( async def generate_image( prompt: str, + width: Optional[int] = None, + height: Optional[int] = None, __request__: Request = None, __user__: dict = None, __event_emitter__: callable = None, @@ -360,6 +362,8 @@ async def generate_image( Generate an image based on a text prompt. :param prompt: A detailed description of the image to generate + :param width: Optional image width in pixels (requires height as well) + :param height: Optional image height in pixels (requires width as well) :return: Confirmation that the image was generated, or an error message """ if __request__ is None: @@ -368,9 +372,13 @@ async def generate_image( try: user = UserModel(**__user__) if __user__ else None + form_kwargs = {'prompt': prompt} + if width is not None and height is not None: + form_kwargs['size'] = f'{width}x{height}' + images = await image_generations( request=__request__, - form_data=CreateImageForm(prompt=prompt), + form_data=CreateImageForm(**form_kwargs), user=user, ) @@ -416,6 +424,8 @@ async def generate_image( async def edit_image( prompt: str, image_urls: list[str], + width: Optional[int] = None, + height: Optional[int] = None, __request__: Request = None, __user__: dict = None, __event_emitter__: callable = None, @@ -428,6 +438,8 @@ async def edit_image( :param prompt: A description of the transformation to apply to the provided images :param image_urls: Source image URLs to modify or use as composition inputs + :param width: Optional output image width in pixels (requires height as well) + :param height: Optional output image height in pixels (requires width as well) :return: Confirmation that the images were edited, or an error message """ if __request__ is None: @@ -436,9 +448,13 @@ async def edit_image( try: user = UserModel(**__user__) if __user__ else None + form_kwargs = {'prompt': prompt, 'image': image_urls} + if width is not None and height is not None: + form_kwargs['size'] = f'{width}x{height}' + images = await image_edits( request=__request__, - form_data=EditImageForm(prompt=prompt, image=image_urls), + form_data=EditImageForm(**form_kwargs), user=user, )