Generate image using curl
The following example demonstrates how to generate an image using the provided JSON payload and curl command. The JSON payload specifies the dimensions, style, and content of the image, including text and an embedded image.
JSON Payload
The JSON payload includes the width and height of the image, background color, and an array of blocks. Each block can be either text or an image, with properties such as position, size, and styling.
Store the following file in data.json.
1touch data.json
1{ 2 "width": 1024, 3 "height": 1024, 4 "imageStyle": { "backgroundColor": "#d13d3d" }, 5 "blocks": [ 6 { 7 "id": "text-1", 8 "type": "text", 9 "x": 195, 10 "y": 145, 11 "fontSize": "80px", 12 "fontStyle": "normal", 13 "fontColor": "red", 14 "text": "Lorem Ipsum", 15 "textAlign": "left", 16 "width": 650, 17 "height": 131, 18 "backgroundColor": "#ffffff", 19 "borderRadius": "25px", 20 "border": "10px solid #000000" 21 }, 22 { 23 "id": "image-2", 24 "type": "image", 25 "x": 315, 26 "y": 372, 27 "image": "https://eoimages.gsfc.nasa.gov/images/imagerecords/153000/153502/michiganfall_vir2_20241019_th.jpg", 28 "width": 413, 29 "height": 405, 30 "borderRadius": "25px", 31 "border": "10px solid #000000" 32 } 33 ] 34}
Checkout the API contract for Image template defined in the API reference for more details on how to format the images.
cURL Command
The curl command sends a POST request to the image generation API endpoint. Replace YOUR_API_KEY with your actual API key. The -d @data.json option specifies the JSON payload file, and the output is saved to image.png.
1curl -X POST https://pixiegenie.saasysoup.com/api/v1/image.png \ 2-H "Content-Type: application/json" \ 3-H "Authorization: Bearer YOUR_API_KEY" \ 4-d @data.json > image.png
Example Output
After running the curl command, the generated image will be saved as image.png in your current directory. You can open this file to see the result of the image generation based on the provided JSON payload.