Created
May 9, 2025 09:01
-
-
Save victor141516/45331289a3bb362b23413fc58b0317b4 to your computer and use it in GitHub Desktop.
Generate image using gpt-image-1
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
function generate_image() { | |
output_filename="image-$(date +%s).png" | |
image_prompt=$(echo $1 | jq -R) | |
gpt_response=$(curl -s https://api.openai.com/v1/images/generations \ | |
-H "Content-Type: application/json" \ | |
-H "Authorization: Bearer $OPENAI_API_KEY" \ | |
-d '{ | |
"model": "gpt-image-1", | |
"prompt": '$image_prompt', | |
"n": 1, | |
"size": "1024x1024" | |
}') | |
echo $gpt_response | jq -r '.data[0].b64_json' | base64 -d > $output_filename || echo $gpt_response | |
realpath "$output_filename" | |
command -v open >/dev/null && open $output_filename | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment