DALL-E Editor: an OpenAI DALL-E app to draw and receive mask edits
version 2024-05-17 - preliminary gpt-images-1
My DALL-E Editor—a practical, feature-rich application built in Python 3.10+, designed specifically to streamline interactions with OpenAI’s DALL-E 2 and DALL-E 3 APIs. This user-friendly GUI application leverages Python’s Tkinter library to simplify image generation, editing, and masking workflows, allowing quick experimentation with AI-generated visuals directly from your desktop.
The main focus is the edits
endpoint for redraw and infill, at $0.02 per image, thus, this has a 1024x1024 image only at this point in development
Key Features and Capabilities:
1. Image Generation from Text Prompts
- Instantly generate high-quality images (1024×1024 pixels) using your descriptive text prompts.
- Choose between DALL-E 2 and DALL-E 3 models effortlessly. gpt-image-1 also there if you ID validate.
- Easily toggle HD mode specifically for DALL-E 3 (or try it’s poorer “natural” style).
- An AI placeholder - develop your own AI calls for prompt improvement, or even prompt library dialog or style (or character) selector.
2. Intuitive Mask Drawing Interface
- Draw precise masks directly on images for targeted editing or inpainting.
- Selectable brush sizes (Small, Medium, Large) to customize mask precision.
- Visual feedback through a semi-transparent red overlay, clearly showing masked regions.
3. Dynamic Image Loading and Scaling
- Load images directly from your file system.
- Interactive slider for dynamically scaling images—choose between cropping to fit or filling (outfill) with optional shrinking allowed, and dragging around.
- Preview adjustments in real-time, allowing precise control of how images fit the target resolution.
- Image transparency is preserved and used for mask also (observe the blue actual size)
4. Integrated Editing Workflow
- Send masked images along with editing prompts to DALL-E’s editing API endpoints seamlessly.
- Smart default prompts when performing outfill operations, simplifying repetitive editing tasks - or what you type
5. Robust Error Handling
- Automatically manages API errors gracefully, ensuring your workflow remains uninterrupted and clear error dialogs inform you promptly.
6. Convenient File Operations
- Easily save your generated and edited images to disk as standard PNG files.
Requirements:
- Python 3.11+
- Pillow: pip install pillow
- OpenAI Python SDK: pip install openai
- Funding your OpenAI account with credits to burn
- Set the environment variable OPENAI_API_KEY with your API key.
The code
Too large for the forum… You just get a docstring…
#!/usr/bin/env python3
"""
dalle_editor.py
A developer-oriented, single-file Tkinter GUI application leveraging OpenAI's DALL·E
API endpoints to create, edit, and refine images via generative AI techniques, including
inpainting, outpainting, and generative fills. Supports:
- loading input files at varying crops or zooms, at canvas position.
- generating 1024x1024 images from textual prompts,
- interactive mask drawing for precise editing,
- robust image editing capabilities.
- copying canvas with transparency, saving to file
------------------------------------------------------------------------------
REQUIRES A TYPICAL OPENAI DEVELOPER ENVIRONMENT ON A DESKTOP OS
------------------------------------------------------------------------------
- Python 3.10+
- dependencies:
- Pillow: `pip install pillow`
- OpenAI: `pip install openai`
- OPENAI_API_KEY environment variable must be set; otherwise,
the application will prompt for a temp API key at startup.
------------------------------------------------------------------------------
CURRENT FEATURES & USAGE PATTERNS
------------------------------------------------------------------------------
- Image Generation:
- Supports OpenAI dall-e-2, dall-e-3, gpt-image-1.
- Dynamically manages advanced parameters (e.g., "HD," "Natural") for DALL·E 3.
- Provides real-time character counters and silent prompt truncation to adhere to
model-specific prompt length constraints.
- gpt-image-1:
- Model does not perform edit without altering and regenerating the whole image.
- Preliminary image + mask support is surfaced, not multiple image re-synthesis.
- No "quality" or "transparency" UI options; only supported on generate
- Mask Drawing & Editing:
- Interactive brush tool enables intuitive mask painting directly onto images, stored
as metadata in a Pillow "L" mode image. A semi-transparent red overlay provides
immediate visual feedback.
- Utilizes OpenAI's images.edit endpoint for precise inpainting and outpainting tasks,
with robust error handling to revert to the last stable image state upon failures.
- Image Import & Export:
- Flexible image loading from disk with dynamic resizing options ("Allow shrink,"
"Allow zoom") to adapt external images into the standardized 1024x1024 workspace.
- Persistent saving of edited images directly to disk for easy workflow integration.
- User Interface:
- Brush size cursor visually indicates mask draw area; mode by its color.
- Contextual right-click menus in text fields offer standard editing operations
(cut, copy, paste, select all).
- Progress indication while making API calls.
- Modular Style:
- Although presented as a single file for clarity, the application is logically
partitioned into distinct sections (API wrapper, dialogs, main editor), each with
minimal global dependencies, future modularization.
- `DalleAPI`: Asynchronous API client for OpenAI's images endpoints.
- `ImageLoadDialog`: Manages image importing and resizing, returning processed images
and masks.
- `DalleEditorApp`: Main GUI class orchestrating UI elements, event handling, and data
flow, supplemented by external utility functions.
------------------------------------------------------------------------------
A ROBUST APPLICATION WOULD OFFER "labs.openai.com" UI and beyond
------------------------------------------------------------------------------
- Larger Scalable Virtual Canvas:
- Images beyond the current 1024x1024 constraint.
- layering, viewport panning, generation and placement, and sectional outfill
- Some "undo" beyond resetting masks
------------------------------------------------------------------------------
AI-Powered Prompting framework for you
------------------------------------------------------------------------------
def ai_rewrite_text(self):
'''a placeholder for an extensive AI-powered function'''
This function is in the right-click menu for both UI prompts.
It will demonstrate readiness by placing a selection within asterisks.
You could develop your own AI language improvers or even dialogs.
"""
Download link
md5sum dalle_editor_2025-05-17.py
a36a27703b154718e7aa3af5c61838cd *dalle_editor_2025-05-17.py
Explore, integrate, and extend freely—DALL-E Editor is designed for developers to adapt, improve, and seamlessly integrate advanced image-generation capabilities directly into their Python applications. If I get around to it - the features of OpenAI’s labs - adding multiple images to a virtual canvas…