Skip to content

Instantly share code, notes, and snippets.

@victor141516
Created May 9, 2025 09:01
Show Gist options
  • Save victor141516/45331289a3bb362b23413fc58b0317b4 to your computer and use it in GitHub Desktop.
Save victor141516/45331289a3bb362b23413fc58b0317b4 to your computer and use it in GitHub Desktop.
Generate image using gpt-image-1
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