Image Mixer
Image Mixer
Interactive CLI tool for batch processing image overlays. Combines base product images with overlay badges/labels to create composite marketing images.
Overview
Image Mixer automates the process of adding overlay badges (like “Dual”, “Lite”, “Metal” rail indicators) to product images. Instead of manually editing each image, you can process multiple base × overlay combinations in one batch operation.
Key Features
- Interactive CLI with step-by-step prompts
- Batch processing for multiple base × overlay combinations
- Configurable positioning and sizing (percentage-based)
- Progress tracking with success/failure reporting
- Automatic directory handling with organized output
Installation
The tool is included in the main project. Install dependencies:
# From project root
pnpm install
# Or install only for image-mixer
cd sub-packages/image-mixer
pnpm install
Usage
Quick Start
# From project root
pnpm image-mixer
# Or from sub-package directory
cd sub-packages/image-mixer
pnpm start
Interactive Workflow
The CLI will guide you through the following steps:
1. Enter Base Image Slugs
Enter image slugs for base images (one per line, press Enter twice to finish):
zb40-red-a-4
zb40-red-a-5
zb40-red-b-2
2. Enter Overlay Image Slugs
Enter image slugs for overlay images (one per line, press Enter twice to finish):
overlay-rail-dual
overlay-rail-lite
overlay-rail-metal
3. Configure Overlay Settings
-
Padding from edges: Distance from right/bottom edge (% of base image)
- Default: 5%
- Range: 0-50%
- Same value applies to both right and bottom edges
-
Overlay width: Width of overlay (% of base image width)
- Default: 35%
- Range: 1-100%
- Height is calculated automatically (1 aspect ratio)
4. Confirm and Process
Review the summary and confirm to start processing:
📋 Summary:
Base images: 3
Overlay images: 3
Total combinations: 9
Padding: 5%
Overlay width: 35%
✓ Proceed with processing? (Y/n)
5. View Results
The tool processes all combinations and shows progress:
🔄 Processing images...
✓ [1/9] zb40-red-a-4--overlay-rail-dual.png
✓ [2/9] zb40-red-a-4--overlay-rail-lite.png
✓ [3/9] zb40-red-a-4--overlay-rail-metal.png
...
✓ Complete! 9 images saved to dist/
Image Processing Details
Source Images
- Location:
/static/images/p/{slug}/mercari.png - Format: PNG files (1600px width)
- Source: Generated by the Image Processor
Output Images
- Directory:
sub-packages/image-mixer/dist/ - Format: PNG
- Naming:
{base-slug}--{overlay-slug}.png - Example:
zb40-red-a-4--overlay-rail-dual.png
Overlay Positioning
Overlays are positioned in the bottom-right corner with:
- Aspect ratio: Always 1 (square)
- Width: Configurable percentage of base image width
- Height: Equal to width (maintains 1 ratio)
- Padding: Distance from right and bottom edges (same value for both)
Calculation Examples
For a 1600px × 1600px base image with default settings (5% padding, 35% width):
- Overlay dimensions: 560px × 560px (35% of 1600px)
- Padding: 80px (5% of 1600px)
- Position: 960px from left, 960px from top
- Right edge: 80px from right edge
- Bottom edge: 80px from bottom edge
Configuration Reference
Padding
Controls distance from right and bottom edges.
| Value | Description | Example (1600px base) |
|---|---|---|
| 3% | Minimal padding | 48px |
| 5% | Default, balanced spacing | 80px |
| 8% | More spacing, safer for crop | 128px |
| 10% | Maximum recommended | 160px |
Overlay Width
Controls size of overlay relative to base image.
| Value | Description | Example (1600px base) |
|---|---|---|
| 25% | Small, subtle overlay | 400px × 400px |
| 35% | Default, balanced size | 560px × 560px |
| 45% | Large, prominent overlay | 720px × 720px |
| 55% | Very large overlay | 880px × 880px |
Error Handling
Common Errors
Missing base image:
✗ Base image not found: /static/images/p/invalid-slug/mercari.png
Solution: Verify the slug is correct and the image exists in /static/images/p/
Missing overlay image:
✗ Overlay image not found: /static/images/p/overlay-invalid/mercari.png
Solution: Ensure overlay images are processed and available in the static directory
Validation
- Slugs: Must be non-empty strings
- Padding: Must be between 0 and 50%
- Overlay width: Must be between 1 and 100%
- Images: Both base and overlay must exist before processing
Tips and Best Practices
Image Preparation
- Process images first: Ensure all base and overlay images are processed by the Image Processor
- Check slugs: Verify slug names match the directory names in
/static/images/p/ - Test with one: Try a single combination first to verify settings
Overlay Design
- Use 1 images: Overlay images should be square for best results
- Add borders: Consider adding white/colored borders to overlay images
- Transparent backgrounds: Overlays can use transparency if needed
Batch Processing
- Group similar products: Process related products together
- Consistent overlays: Use the same overlay set across product variants
- Verify before batch: Test configuration with a small batch first
File Organization
- Output directory:
dist/is gitignored, move files as needed - Naming convention:
{base}--{overlay}.pngmakes it easy to identify combinations - Cleanup: Remove old files from
dist/before new batch processing
Integration with Image Processor
Image Mixer works seamlessly with the Image Processor:
- Source images: Uses
mercari.pngfiles generated by Image Processor - Slug system: Follows the same slug-based directory structure
- Image format: Compatible with processed PNG outputs
Workflow Example
# 1. Process original images
pnpm convimgs
# 2. Run image mixer
pnpm image-mixer
# 3. Use output images for marketing/listings
Troubleshooting
CLI doesn’t start
Issue: command not found or permission error
Solution:
cd sub-packages/image-mixer
chmod +x bin/image-mixer.mjs
pnpm install
Images not found
Issue: “Base image not found” errors
Solution:
- Check if slug exists:
ls static/images/p/{slug}/ - Verify mercari.png exists:
ls static/images/p/{slug}/mercari.png - Process images if missing:
pnpm convimgs {original-filename}
Wrong positioning
Issue: Overlay appears in wrong position or size
Solution:
- Check configuration values (padding, overlay width)
- Verify base image dimensions are correct
- Test with different percentage values
Output quality issues
Issue: Pixelated or low-quality output
Solution:
- Image Mixer uses Sharp with PNG output at maximum quality
- Check source images (mercari.png) are high quality (1600px width)
- Verify overlay images are high resolution
Technical Details
Dependencies
- sharp: Image processing and compositing
- prompts: Interactive CLI prompts
- chalk: Terminal color output
Architecture
sub-packages/image-mixer/
├── bin/
│ └── image-mixer.mjs # CLI entry point
├── src/
│ └── image-processor.mjs # Core processing logic
├── dist/ # Output directory (gitignored)
├── package.json
└── README.md
Image Processing Pipeline
- Load base image from
/static/images/p/{base-slug}/mercari.png - Load overlay image from
/static/images/p/{overlay-slug}/mercari.png - Get base dimensions using Sharp metadata
- Calculate overlay size (width × width for 1 ratio)
- Calculate position (bottom-right with padding)
- Resize overlay to calculated dimensions
- Composite images using Sharp composite API
- Output PNG to
dist/{base}--{overlay}.png
Related Documentation
- Image Processor - Process original images to generate mercari.png files
- Sub Packages Overview - Other development tools and utilities