AI Preview Image Generator¶
Automatically generate preview images for your posts and pages using AI image generation services.
Overview¶
The preview image generator provides:
- AI-Powered: Uses OpenAI (GPT Image or DALL-E 3), Stability AI, or a local placeholder
- Jekyll Integration: Liquid tags and filters
- Configurable Style: Default retro pixel art aesthetic
- Batch Generation: Process multiple posts at once (parallel workers)
How It Works¶
graph LR
A[Post without preview] --> B[Generate prompt from title/description]
B --> C{Provider}
C -->|OpenAI| D[GPT Image / DALL-E API]
C -->|Stability| E[Stability AI]
C -->|local| F[Local placeholder]
D --> G[Save image]
E --> G
F --> G
G --> H[Update front matter]
Configuration¶
Basic Setup¶
# _config.yml
preview_images:
enabled: true
provider: openai # openai, stability, local
auto_generate: false # Generate during build
Full Configuration¶
preview_images:
enabled: true
provider: openai # openai, stability, local
model: gpt-image-2 # gpt-image-2, dall-e-3, dall-e-2, stable-diffusion
size: 1536x1024 # GPT Image landscape; DALL-E 3 also supports 1792x1024
quality: auto # auto for GPT Image; standard/hd for DALL-E 3
style: "retro pixel art, 8-bit video game aesthetic, vibrant colors"
style_modifiers: "pixelated, retro gaming style, CRT screen glow effect"
output_dir: assets/images/previews
assets_prefix: /assets
auto_prefix: true
auto_generate: false
collections: # plugin default if omitted
- posts
- docs
- quickstart
The values above match the shipped _config.yml. collections is not set in the shipped config but defaults to [posts, docs, quickstart] in the plugin (_plugins/preview_image_generator.rb).
API Keys¶
Set environment variables:
Usage¶
Manual Generation¶
Run the generation script:
# Generate for all posts without previews
./scripts/generate-preview-images.sh
# Generate for specific post
./scripts/generate-preview-images.sh --file pages/_posts/2025-01-25-my-post.md
# Dry run (preview what would be generated)
./scripts/generate-preview-images.sh --dry-run
Liquid Tags¶
<!-- Show count of missing previews -->
{% preview_image_status %}
<!-- Get preview image path -->
{{ page | preview_image_path }}
<!-- Check if page has preview -->
{% if page | has_preview_image %}
<img src="{{ page.preview | relative_url }}" alt="Preview">
{% endif %}
In Front Matter¶
Providers¶
OpenAI (GPT Image / DALL-E 3)¶
Best quality. The shipped default is the GPT Image model; DALL-E 3 is also supported:
preview_images:
provider: openai
model: gpt-image-2 # default; or dall-e-3, dall-e-2
size: 1536x1024 # GPT Image landscape; DALL-E 3 also takes 1792x1024
quality: auto # auto for GPT Image; standard/hd for DALL-E 3
Stability AI¶
Good alternative. Set provider: stability and supply STABILITY_API_KEY. The script calls the Stable Diffusion XL 1024 endpoint at 1024x1024 — there is no separate engine/size key to set for this provider:
preview_images:
provider: stability
# Uses STABILITY_API_KEY; generates 1024x1024 via Stable Diffusion XL
Local (placeholder)¶
Free, no API needed. The local provider writes a .txt placeholder next to the target path instead of calling an image API — useful for development and dry runs:
Style Customization¶
Default Style¶
The default generates retro pixel art:
style: "retro pixel art, 8-bit video game aesthetic, vibrant colors, nostalgic"
style_modifiers: "pixelated, retro gaming style, CRT screen glow effect"
Professional Style¶
style: "professional, modern, clean, minimalist design"
style_modifiers: "corporate, business, elegant, high quality"
Artistic Style¶
style: "watercolor painting, artistic, creative"
style_modifiers: "hand-painted, artistic texture, vibrant colors"
Custom Per-Post¶
Plugin Details¶
File Location¶
Available Methods¶
# Check if document has preview
PreviewImageGenerator.has_preview?(doc)
# Get preview path
PreviewImageGenerator.preview_path(doc)
# Generate prompt from document
PreviewImageGenerator.generate_prompt(doc)
Liquid Filters¶
| Filter | Description |
|---|---|
preview_image_path |
Returns full preview image path |
has_preview_image |
Returns true if preview exists |
Liquid Tags¶
| Tag | Description |
|---|---|
{% preview_image_status %} |
Shows missing preview count |
Image Specifications¶
Recommended Sizes¶
| Platform | Size | Aspect |
|---|---|---|
| Open Graph | 1200×630 | 1.91:1 |
| 1200×600 | 2:1 | |
| DALL-E 3 | 1792×1024 | 1.75:1 |
Output Directory¶
Images saved to:
Automatic Generation¶
During Build¶
Enable auto-generation (slow!):
GitHub Actions¶
Add to CI workflow:
- name: Generate preview images
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: ./scripts/generate-preview-images.sh
Cost Considerations¶
OpenAI DALL-E 3¶
- Standard quality: ~$0.04 per image
- HD quality: ~$0.08 per image
Budget Tips¶
- Use placeholder during development
- Generate only for published posts
- Batch generate periodically
- Cache generated images
Troubleshooting¶
API Key Not Found¶
Generation Failed¶
- Check API key validity
- Verify API quota
- Check network connection
- Review error logs
Wrong Image Path¶
- Check
assets_prefixconfig - Verify
output_direxists - Check front matter path
Images Not Showing¶
- Verify file exists at path
- Check Jekyll build includes assets
- Clear browser cache
- Check relative URL helper
Related¶
Technical Reference¶
For implementation details (multi-provider architecture, xAI Grok integration, generation workflow):