Last active
May 15, 2026 08:20
-
-
Save tai2/b9db2fd2de608468820916b37de31522 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| usage() { | |
| echo "Usage: $0 -p <prompt> -o <output_file> [-m <model>] [-s <size>]" | |
| echo "" | |
| echo " -p Prompt text (required)" | |
| echo " -o Output filename (required)" | |
| echo " -m Model (default: dall-e-2)" | |
| echo " -s Size (default: 1024x1024)" | |
| exit 1 | |
| } | |
| MODEL="gpt-image-1-mini" | |
| SIZE="1024x1024" | |
| PROMPT="" | |
| OUTPUT="" | |
| while getopts "p:o:m:s:h" opt; do | |
| case $opt in | |
| p) PROMPT="$OPTARG" ;; | |
| o) OUTPUT="$OPTARG" ;; | |
| m) MODEL="$OPTARG" ;; | |
| s) SIZE="$OPTARG" ;; | |
| h) usage ;; | |
| *) usage ;; | |
| esac | |
| done | |
| [[ -z "$PROMPT" || -z "$OUTPUT" ]] && usage | |
| if [[ -z "${OPENAI_API_KEY:-}" ]]; then | |
| echo "Error: OPENAI_API_KEY is not set" >&2 | |
| exit 1 | |
| fi | |
| echo "Generating image..." | |
| curl -sf https://api.openai.com/v1/images/generations \ | |
| -H "Content-Type: application/json" \ | |
| -H "Authorization: Bearer $OPENAI_API_KEY" \ | |
| -d "$(jq -n \ | |
| --arg model "$MODEL" \ | |
| --arg prompt "$PROMPT" \ | |
| --arg size "$SIZE" \ | |
| '{model: $model, prompt: $prompt, n: 1, size: $size}')" \ | |
| | jq --raw-output '.data[0].b64_json' \ | |
| | base64 --decode > "$OUTPUT" | |
| echo "Saved to $OUTPUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment