Skip to content

CrabAI/image_text_editor_agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

image_text_editor_agent

A lightweight Streamlit image text editor that lets you select a text area on an uploaded image, cover that area, render new Korean or English text, and download the edited result as a PNG.

Features

  • Image Upload: Supports PNG, JPG, JPEG, and WEBP files
  • Canvas Area Selection: Draws a rectangle over the text area to edit
  • Local Text Replacement: Covers only the selected area and renders replacement text
  • Korean Font Support: Loads .ttf, .otf, and .ttc fonts from the fonts/ directory
  • Text Styling Controls: Adjusts font, size, color, alignment, and line spacing
  • Background Cover Options: Uses surrounding average color or a manually selected solid color
  • PNG Export: Downloads the edited image locally

Requirements

  • Python 3.9+
  • Streamlit
  • streamlit-drawable-canvas
  • Pillow
  • NumPy

Installation

1. Clone the repository

git clone https://github.com/CrabAI/image_text_editor_agent.git
cd image_text_editor_agent

2. Create a virtual environment (optional)

python -m venv .venv
source .venv/bin/activate

3. Install dependencies

pip install -r requirements.txt

Usage

streamlit run app.py

Open the Streamlit URL, upload an image, draw a rectangle over the text you want to replace, adjust the edit settings, apply the change, and download the PNG result.

Example Flow

Image text editor
1. Upload a PNG, JPG, JPEG, or WEBP image
2. Draw a rectangle around the text area
3. Enter replacement text
4. Choose font, size, color, alignment, spacing, and cover mode
5. Apply the edit to the selected area
6. Download the edited image as PNG

Output Files

  • edited_image.png: Downloaded PNG created from the current edited image

The app does not save uploaded or edited images to the repository by default.

Project Structure

image_text_editor_agent/
├── app.py
├── requirements.txt
├── .gitignore
├── README.md
├── fonts/
│   ├── Paperlogy-1Thin.ttf
│   ├── Paperlogy-2ExtraLight.ttf
│   ├── Paperlogy-3Light.ttf
│   ├── Paperlogy-4Regular.ttf
│   ├── Paperlogy-5Medium.ttf
│   ├── Paperlogy-6SemiBold.ttf
│   ├── Paperlogy-7Bold.ttf
│   ├── Paperlogy-8ExtraBold.ttf
│   └── Paperlogy-9Black.ttf
└── image_text_editor/
    ├── __init__.py
    ├── editor.py
    ├── font_manager.py
    ├── image_io.py
    └── text_layout.py

Font Notes

Korean text needs a Korean-capable font in fonts/. This repository includes Paperlogy font files for local rendering. You can also add fonts such as Noto Sans KR, Pretendard, or NanumGothic.

How It Works

Uploaded image
       |
       v
Canvas rectangle selection
       |
       v
Normalize selected box to source image coordinates
       |
       v
Cover selected area with average or solid background color
       |
       v
Wrap and render replacement text inside the box
       |
       v
Download edited PNG

Privacy And Git Hygiene

  • .env and .streamlit/secrets.toml are not tracked
  • Local output, upload, download, log, cache, and virtual environment files are not tracked
  • Uploaded images are handled in the Streamlit session and are not saved by the app by default
  • Avoid committing personal photos, customer screenshots, confidential documents, or generated private outputs
  • Review edited images before sharing them externally

Troubleshooting

Font cannot be loaded

  • Make sure the font file exists in fonts/
  • Use .ttf, .otf, or .ttc font files
  • Confirm the font supports the characters you want to render

Text does not fit in the selected area

  • Increase the rectangle size
  • Reduce the font size
  • Reduce line spacing
  • Use a shorter replacement phrase

Background cover does not match perfectly

  • Try the manual solid color option
  • Select a slightly larger rectangle around the original text
  • Complex gradients or textured backgrounds may need manual image editing

License

MIT

About

Streamlit image text editor for replacing selected text areas and exporting edited PNGs

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages