Skip to content

Generate Images

Asterios Raptis edited this page Aug 5, 2025 · 5 revisions

πŸ–Ό Generate and Inject Chapter Images

Updated for:

  • βœ… Default paths for prompt file and output directory

  • βœ… Chapter-based prompts

  • βœ… Character profile injection

  • βœ… Style override support

  • βœ… CLI overrides (e.g., API key)

  • βœ… Auto-skip existing images


πŸ“Œ Overview

Task File / Script Description
🧠 Generate images scripts/generate_images.py Creates images using DeepAI based on structured JSON prompt files
✍️ Inject into chapters scripts/inject_images.py Inserts ![image](...) tags into Markdown files
🧰 Character descriptions scripts/data/character_profiles.json Stores reusable character descriptions for image prompts
🧰 Prompt JSON file scripts/data/image_prompts.json Default prompt template with chapters, characters, and prompts

πŸ“ Directory Structure (Example)

project-root/
β”œβ”€β”€ manuscript/
β”‚   └── chapters/
β”‚       β”œβ”€β”€ 01-holiday-in-ohio.md
β”‚       └── ...
β”œβ”€β”€ assets/
β”‚   β”œβ”€β”€ illustrations/                     ← πŸ–Ό Output images (default)
β”‚   └── prompts/
β”‚       └── holiday_ch1_prompts.json       ← Alternative prompt file (optional)
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ generate_images.py                 ← 🧠 Image generation logic
β”‚   └── inject_images.py                   ← ✍️  Markdown image injection
β”‚
β”œβ”€β”€ scripts/data/
β”‚   β”œβ”€β”€ character_profiles.json            ← Character descriptions
β”‚   └── image_prompts.json                 ← Default prompt file used by script
β”‚
β”œβ”€β”€ .env                                   ← Set your API key here

βš™οΈ Setup

  1. Install dependencies
poetry install
  1. Set your DeepAI API key in .env
DEEPAI_API_KEY=your_deepai_key_here
  1. Optional: Register CLI shortcuts
[tool.poetry.scripts]
generate-images = "scripts.generate_images:main"
inject-images = "scripts.inject_images:main"

🧠 Step 1: Create Prompt JSON File

The file must define a style and a list of chapters. Each chapter contains image prompts with optional character references.

Example (scripts/data/image_prompts.json):

{
  "style": "comic book, colorful, cinematic lighting",
  "chapters": [
    {
      "title": "Chapter 1 – Arrival",
      "prompts": [
        {
          "character": ["Chris", "Das Auto"],
          "prompt": "driving toward a city sign that says 'Welcome to Ohio', excited faces",
          "filename": "holiday_ch1_01_arrival.png"
        },
        {
          "character": "Hotelbesitzer",
          "prompt": "lurking behind the hotel desk, eyes glowing",
          "filename": "holiday_ch1_04_owner.png"
        }
      ]
    }
  ]
}

πŸ‘₯ Step 2: Create Character Profiles

Stored in scripts/data/character_profiles.json:

{
  "Chris": "a cartoon boy around 13 years old, clever, casual travel clothes, comic style",
  "Das Auto": "a shiny red convertible with a white racing stripe",
  "Hotelbesitzer": "a creepy cartoon hotel owner with glowing eyes and wild hair, comic horror"
}

🎨 Step 3: Generate Images

🧾 Using Defaults (no arguments)

poetry run generate-images

This uses:

  • Prompt file: scripts/data/image_prompts.json

  • Output directory: assets/illustrations

🧾 With Custom Prompt File or Output Directory

poetry run generate-images \
  --prompt-file assets/prompts/holiday_ch1_prompts.json \
  --output-dir assets/illustrations

πŸ” Use a different API key

poetry run generate-images \
  --api-key sk-your-deepai-key

If --api-key is omitted, the script uses the value from .env.


✍️ Step 4: Inject Images into Markdown Chapters

poetry run inject-images

πŸ§ͺ Dry-run

poetry run inject-images --dry-run

Adds image markdown like:

![image](../assets/illustrations/holiday_ch1_01_arrival.png)

🧾 Example Summary Output

πŸ“„ Chapters processed:    1
🧠 Prompts in total:     5
βœ… Images generated:     4
⏭️  Skipped (exists):    1
❌ Errors:               0

βœ… Tips

  • Use consistent filenames like holiday_ch1_01_arrival.png

  • Define default prompt styles to unify your visual output

  • Separate characters from prompts for modularity

  • Use --api-key to override or rotate credentials

  • Works great with inject-images and Pandoc/HTML exporters


Clone this wiki locally