A command-line tool for generating D&D SRD subject images using AI. This tool creates high-quality, stylized images of D&D subjects (items, monsters, weapons, spells, etc.) in the iconic 90s TSR catalog style.
- Generate detailed image prompts using AI
- Create high-quality D&D subject images
- Save images in PNG format
- Command-line interface for easy use
- Configurable through environment variables
- Batch processing of multiple subjects
- Rate limiting to respect API limits
- Go 1.23 or later
- OpenAI API key
go install github.com/5e-bits/dndimg@latestgit clone https://github.com/5e-bits/dndimg.git
cd dndimg
go installCreate a .env file in your working directory with the following variables:
OPENAI_API_KEY=your_api_key_hereThe tool uses a default system prompt that guides the AI in generating D&D-themed images in the 90s TSR catalog style. You can override this by setting the SYSTEM_PROMPT environment variable.
Default system prompt:
You are an expert in Dungeons & Dragons art direction, specializing in the iconic 90s TSR catalog style. Your task is to create focused, clear descriptions that depict individual D&D subjects (items, monsters, weapons, spells, etc.) in a way that would fit perfectly in a D&D catalog or rulebook. Focus on clear, isolated depictions that showcase the subject's key features while maintaining the dramatic, high-fantasy aesthetic of classic TSR-era hand-painted artwork. Ensure the descriptions emphasize traditional painting techniques, brush strokes, and artistic style rather than photographic realism.
The tool also uses a default web search prompt to guide the AI in researching and analyzing D&D subjects. You can override this by setting the WEB_SEARCH_PROMPT environment variable.
Default web search prompt:
Research and analyze this D&D subject, focusing on:
1. Core visual characteristics and defining features
2. Historical context and significance in D&D lore
3. Typical appearance and key details
4. Common interactions or effects (if applicable)
5. Key artistic elements from 90s D&D catalog style (clear composition, dramatic lighting, rich textures, hand-painted aesthetic)
Generate a detailed description that would serve as a perfect prompt for creating a piece of hand-painted art that could have appeared in a 90s D&D catalog or rulebook.
To use custom prompts, add them to your .env file:
SYSTEM_PROMPT=your_custom_system_prompt_here
WEB_SEARCH_PROMPT=your_custom_web_search_prompt_hereGenerate an image for any D&D subject:
dndimg "Ancient Red Dragon"The tool will:
- Generate a detailed description of the subject
- Create an image based on the description
- Save the image as a PNG file in the current directory
Process multiple subjects from a file:
dndimg -f subjects.txtWhere subjects.txt contains one subject per line:
Ancient Red Dragon
Beholder
Mind Flayer
You can also use different delimiters by setting the SUBJECTS_DELIMITER environment variable:
# For comma-separated values
SUBJECTS_DELIMITER=, dndimg -f subjects.csv
# For semicolon-separated values
SUBJECTS_DELIMITER=; dndimg -f subjects.txt
# For newline-separated values (default)
SUBJECTS_DELIMITER=\n dndimg -f subjects.txtThe tool will:
- Process each subject in sequence
- Respect API rate limits (1 request per 20 seconds)
- Show progress for each subject
- Continue processing if any subject fails
- Provide a summary of successful and failed subjects
You can use this tool in GitHub Actions to automatically generate images. Here's an example workflow:
name: Generate D&D Images
on:
workflow_dispatch:
inputs:
subjects:
description: 'Subjects to generate images for (comma or semicolon separated)'
required: true
type: string
jobs:
generate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'
- name: Install dndimg
run: go install github.com/5e-bits/dndimg@latest
- name: Generate Images
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
SUBJECTS_DELIMITER: ',' # or ';' for semicolon-separated values
run: |
echo "${{ github.event.inputs.subjects }}" > subjects.txt
dndimg -f subjects.txt
- name: Upload Images
uses: actions/upload-artifact@v4
with:
name: dnd-images
path: "*.png"To use this workflow:
- Add your OpenAI API key as a repository secret named
OPENAI_API_KEY - Go to the Actions tab in your repository
- Select the "Generate D&D Images" workflow
- Click "Run workflow"
- Enter your subjects as a comma-separated list (e.g., "Ancient Red Dragon, Beholder, Mind Flayer") or semicolon-separated list (e.g., "Ancient Red Dragon; Beholder; Mind Flayer")
- Click "Run workflow" to start the process
The generated images will be available as artifacts in the workflow run.
Note: Using comma or semicolon delimiters is recommended for GitHub Actions as they work better with the workflow input format than newlines. Make sure to set the SUBJECTS_DELIMITER environment variable to match your chosen delimiter (',' or ';').
# Generate an image of a weapon
dndimg "Heavy crossbow"
# Generate an image of a monster
dndimg "Brown Bear"
# Generate an image of a spell
dndimg "Chill touch"
# Process multiple subjects from a file
dndimg -f subjects.txt- github.com/alecthomas/kong - Command-line argument parsing
- github.com/charmbracelet/log - Logging
- github.com/sashabaranov/go-openai - OpenAI API client
go build -o dndimg cmd/dndimg/main.goThis project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.