Skip to content
jsontoimg
Start free

SDKs and reference

PHP

There is no official PHP package yet. On WordPress, use the plugin instead of raw cURL. Otherwise use cURL (or Guzzle) against the same HTTP API as Quick Start.

<?php
$base = getenv('JSONTOIMG_BASE_URL'); // e.g. https://app.jsontoimg.com
$key = getenv('JSONTOIMG_API_KEY');

$ch = curl_init($base . '/api/v1/render?wait=60');
curl_setopt_array($ch, [
  CURLOPT_POST => true,
  CURLOPT_HTTPHEADER => [
    'Authorization: Bearer ' . $key,
    'Content-Type: application/json',
  ],
  CURLOPT_POSTFIELDS => json_encode([
    'template' => '<design-id>',
    'format' => 'png',
    'layers' => ['headline' => ['text' => 'Hello']],
  ]),
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_TIMEOUT => 90,
]);

$body = curl_exec($ch);
curl_close($ch);
$job = json_decode($body, true);
echo $job['status'], ' ', $job['assetUrl'] ?? '', "\n";

Auth, errors, and wait/SSE behave like the API reference. For Node.js, use the typed SDK.