Generate an image

Before generating images, you must first have a template to apply.

You can create or clone templates directly on the web app.

These are the parameters that should go in the request.

The "transformation" object indicates to the API which transformation to perform to the template.

POST https://api.picsapi.com/v1/render

Request Body

NameTypeDescription

template_id*

String

The ID of the template.

transformations*

Object

The transformations that you'd like to perform.

The transformation object should contain the layers that you want to edit.

If we want to edit the layers title and article_image

The body object looks like this:

{
  "template_id": "<template-id>",
  "transformations": {
    "title": {
      "color": "rgb(0,0,0)",
      "font_size": "55",
      "text_align": "center",
      "font_family": "Arial",
      "text": "Text to enter"
    },
    "article_image": {
      "src": "https://link.com/image.jpg"
    }
  }

Code Examples

cURL

curl -X "POST" "https://api.picsapi.com/v1/render" \
     -H 'Authorization: Bearer <api-token>' \
     -H 'Content-Type: application/json; charset=utf-8' \
     -d $'{
  "template_id": "<template-id>",
  "transformations": {
    "price": {
      "color": "rgb(0,0,0)",
      "font_size": "32",
      "text_align": "center",
      "font_family": "Arial",
      "text": "Text to enter"
    }
  }
}'

PHP cURL

<?php

// get cURL resource
$ch = curl_init();

// set url
curl_setopt($ch, CURLOPT_URL, 'https://api.picsapi.com/v1/render');

// set method
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST');

// return the transfer as a string
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

// set headers
curl_setopt($ch, CURLOPT_HTTPHEADER, [
  'Authorization: Bearer <api-token>',
  'Content-Type: application/json; charset=utf-8',
]);

// json body
$json_array = [
  'template_id' => '<template-id>',
  'transformations' => [
    'price' => [
      'color' => 'rgb(0,0,0)',
      'font_family' => 'Arial',
      'font_size' => '32',
      'text_align' => 'center',
      'text' => 'Text to enter'
    ]
  ]
]; 
$body = json_encode($json_array);

// set body
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);

// send the request and save response to $response
$response = curl_exec($ch);

// stop if fails
if (!$response) {
  die('Error: "' . curl_error($ch) . '" - Code: ' . curl_errno($ch));
}

echo 'HTTP Status Code: ' . curl_getinfo($ch, CURLINFO_HTTP_CODE) . PHP_EOL;
echo 'Response Body: ' . $response . PHP_EOL;

// close curl resource to free up system resources 
curl_close($ch);
<?php

// Include Guzzle. If using Composer:
// require 'vendor/autoload.php';

use GuzzleHttp\Pool;
use GuzzleHttp\Client;
use GuzzleHttp\Psr7\Request;

$client = new Client();

$request = new Request(
        "POST",
        "https://api.picsapi.com/v1/render",
        [
            "Authorization" => "Bearer <api-key>",
            "Content-Type" => "application/json; charset=utf-8"
        ],
        "{\"template_id\":\"<template-id>\",\"transformations\":{\"price\":{\"text\":\"Text to enter\",\"color\":\"rgb(0,0,0)\",\"font_family\":\"Arial\",\"font_size\":\"32\",\"text_align\":\"center\"}}}");

$response = $client->send($request);
echo "Response HTTP : " . $response->getStatusCode() . "
";

NodeJS (Axios)

axios({
	"method": "POST",
	"url": "https://api.picsapi.com/v1/render",
	"headers": {
		"Authorization": "Bearer <api-token>",
		"Content-Type": "application/json; charset=utf-8"
	},
	"data": {
		"template_id": "<template-id>",
		"transformations": {
			"price": {
			      "color": "rgb(0,0,0)",
			      "font_size": "32",
			      "text_align": "center",
			      "font_family": "Arial",
			      "text": "Text to enter"
			}
		}
	}
})

NodeJS (http/s)

 (function(callback) {
    'use strict';
        
    const httpTransport = require('http');
    const responseEncoding = 'utf8';
    const httpOptions = {
        hostname: 'api.picsapi.com',
        port: '443',
        path: '/v1/render',
        method: 'POST',
        headers: {"Authorization":"Bearer <api-token>","Content-Type":"application/json; charset=utf-8"}
    };
    httpOptions.headers['User-Agent'] = 'node ' + process.version;

    const request = httpTransport.request(httpOptions, (res) => {
        let responseBufs = [];
        let responseStr = '';
        
        res.on('data', (chunk) => {
            if (Buffer.isBuffer(chunk)) {
                responseBufs.push(chunk);
            }
            else {
                responseStr = responseStr + chunk;            
            }
        }).on('end', () => {
            responseStr = responseBufs.length > 0 ? 
                Buffer.concat(responseBufs).toString(responseEncoding) : responseStr;
            
            callback(null, res.statusCode, res.headers, responseStr);
        });
        
    })
    .setTimeout(0)
    .on('error', (error) => {
        callback(error);
    });
    request.write("{\"template_id\":\"<template-id>\",\"transformations\":{\"price\":{\"text\":\"Text to enter\",\"color\":\"rgb(0,0,0)\",\"font_family\":\"Arial\",\"font_size\":\"32\",\"text_align\":\"center\"}}}")
    request.end();
    

})((error, statusCode, headers, body) => {
    console.log('ERROR:', error); 
    console.log('STATUS:', statusCode);
    console.log('HEADERS:', JSON.stringify(headers));
    console.log('BODY:', body);
});

Last updated