A TypeScript-based command-line tool for generating AI images with custom sizes using OpenAI DALL-E.
- Generate AI images from text prompts using DALL-E 3
- Support for custom aspect ratios (e.g., 3:2, 16:9) and dimensions (e.g., 1920x1080)
- Automatic image resizing and cropping to exact specifications
- Multiple output formats (PNG, JPG, WebP)
- Quality options (standard, HD)
- Style options (natural, vivid)
- Secure API key management
npx @tmgbabul/ai-image-gen generate "A serene mountain landscape" --size 3:2npm install -g @tmgbabul/ai-image-gen
@tmgbabul/ai-image-gen generate "A serene mountain landscape" --size 3:2npm install @tmgbabul/ai-image-gen
npx @tmgbabul/ai-image-gen generate "A serene mountain landscape" --size 3:2Before using the CLI, set your OpenAI API key:
npx @tmgbabul/ai-image-gen config set OPENAI_API_KEY sk-xxxxxAlternatively, set the environment variable:
export OPENAI_API_KEY=sk-xxxxx# Set a config value
npx @tmgbabul/ai-image-gen config set OPENAI_API_KEY sk-xxxxx
# Get a config value
npx @tmgbabul/ai-image-gen config get OPENAI_API_KEY
# Delete a config value
npx @tmgbabul/ai-image-gen config delete OPENAI_API_KEY
# List all config values
npx @tmgbabul/ai-image-gen config listConfiguration is stored in ~/.@tmgbabul/ai-image-gen/config.json.
npx @tmgbabul/ai-image-gen generate "A serene mountain landscape at sunset"If installed globally:
@tmgbabul/ai-image-gen generate "A serene mountain landscape at sunset"# Generate with custom aspect ratio
npx @tmgbabul/ai-image-gen generate "Blog header image" --size 3:2 --output header.png
# Generate with custom dimensions
npx @tmgbabul/ai-image-gen gen "Featured image" -s 1920x1080 -o featured.png
# Generate with HD quality and vivid style
npx @tmgbabul/ai-image-gen gen "Sunset over ocean" -s 16:9 -q hd --style vivid
# Generate as JPG
npx @tmgbabul/ai-image-gen gen "Product photo" -s 1024x768 -f jpg| Option | Alias | Type | Default | Description |
|---|---|---|---|---|
<prompt> |
- | string | required | Image description |
--size |
-s |
string | 1024x1024 |
Aspect ratio (3:2) or dimensions (1024x768) |
--output |
-o |
string | ./image-{timestamp}.png |
Output file path |
--quality |
-q |
enum | standard |
standard or hd |
--style |
- | enum | natural |
vivid or natural |
--model |
-m |
string | dall-e-3 |
OpenAI model |
--format |
-f |
enum | png |
png, jpg, webp |
Blog post hero image (3:2 aspect ratio):
npx @tmgbabul/ai-image-gen gen "Modern office workspace" -s 3:2 -o blog-hero.pngWide banner (16:9):
npx @tmgbabul/ai-image-gen gen "Technology background" -s 16:9 -q hdSocial media post (1080x1080):
npx @tmgbabul/ai-image-gen gen "Inspirational quote background" -s 1080x1080Custom dimensions:
npx @tmgbabul/ai-image-gen gen "Website header" -s 1920x600 -f webpDALL-E only supports three fixed sizes: 1024x1024, 1792x1024, and 1024x1792. This CLI handles custom sizes by:
- Mapping your requested size to the closest DALL-E size
- Generating the image at the DALL-E size
- Using Sharp to resize/crop to your exact dimensions
Examples:
- 3:2 (1536x1024) → Generate at 1792x1024, crop to 1536x1024
- 16:9 (1920x1080) → Generate at 1792x1024, resize to 1920x1080
- 1024x768 → Generate at 1024x1024, resize to 1024x768
# Install dependencies
npm install
# Build
npm run build
# Type check
npm run typecheck
# Development mode
npm run dev@tmgbabul/ai-image-generator/
├── bin/
│ └── cli.js # Shebang entry point
├── src/
│ ├── index.ts # CLI entry with Commander
│ ├── commands/
│ │ ├── generate.ts # Image generation command
│ │ └── config.ts # Configuration command
│ ├── services/
│ │ ├── openai.ts # OpenAI API wrapper
│ │ └── image-processor.ts # Sharp-based processing
│ ├── utils/
│ │ ├── size-mapper.ts # Size mapping logic
│ │ ├── config-manager.ts # Config file handling
│ │ └── validators.ts # Input validation
│ └── types/
│ └── index.ts # TypeScript interfaces
├── package.json
├── tsconfig.json
└── tsup.config.ts
The CLI provides helpful error messages:
✗ OpenAI API key not found. Run: @tmgbabul/ai-image-gen config set OPENAI_API_KEY sk-xxxxx✗ Invalid size format. Use aspect ratio (e.g., 3:2) or dimensions (e.g., 1024x768)✗ Quality 'hd' requires dall-e-3 model
- Node.js 18 or higher
- OpenAI API key with DALL-E access
MIT