Orshot Logo
OrshotDocs

PHP

Get started with Orshot PHP SDK

Installation

composer require rishimohan/orshot

Render from template

$response = $client->renderFromTemplate([
  'templateId'=> 'open-graph-image-1',
  'modifications' => $modifications,
  'responseType'=> 'url',
  'responseFormat' => 'png'
]);

Generate a Signed URL

$signed_response = $client->generateSignedUrl([
  'templateId'=> 'open-graph-image-1',
  'expiresAt' => 1744276943,
  'modifications' => $modifications,
  'renderType'=> 'images',
  'responseFormat' => 'png'
]);

Examples

base64 response format

<?php
require 'vendor/autoload.php';
use Orshot\Client;
$client = new Client("<ORSHOT_API_KEY>");
$modifications = [
  'title' => 'Title from PHP SDK.',
  'description' => 'Description from PHP SDK.'
];
$response = $client->renderFromTemplate([
  'templateId'=> 'open-graph-image-1',
  'modifications' => $modifications,
  'responseType'=> 'base64',
  'responseFormat' => 'png'
]);

url response format

<?php
require 'vendor/autoload.php';
use Orshot\Client;
$client = new Client("<ORSHOT_API_KEY>");
$modifications = [
  'title' => 'Title from PHP SDK.',
  'description' => 'Description from PHP SDK.'
];
$response = $client->renderFromTemplate([
  'templateId'=> 'open-graph-image-1', 
  'modifications' => $modifications, 
  'responseType'=> 'url', 
  'responseFormat' => 'png'
]);

binary response format

<?php
 
require 'vendor/autoload.php';
 
use Orshot\Client;
 
$client = new Client("<ORSHOT_API_KEY>");
 
$modifications = [
    'title' => 'Title from PHP SDK.',
    'description' => 'Description from PHP SDK.'
];
 
$response = $client->renderFromTemplate(['templateId'=> 'open-graph-image-1', 'modifications' => $modifications, 'responseType'=> 'binary', 'responseFormat' => 'png']);
file_put_contents('og.png', $response);

This example writes the binary image to the file og.png

Signed URL

<?php
 
require 'vendor/autoload.php';
 
use Orshot\Client;
 
$client = new Client("<ORSHOT_API_KEY>");
 
$modifications = [
  'title' => 'Title from PHP SDK.',
  'description' => 'Description from PHP SDK.'
];
 
$signed_response = $client->generateSignedUrl([
  'templateId'=> 'open-graph-image-1',
  'expiresAt' => 1744276943,
  'modifications' => $modifications,
  'renderType'=> 'images',
  'responseFormat' => 'png'
]);

Output

Array
(
  [url] => https://api.orshot.com/v1/generate/images?description=Description%20from%20PHP%20SDK.&expiresAt=1744276943&id=36&templateId=open-graph-image-1&title=Title%20from%20PHP%20SDK.&signature=7ede3e531de82cbage6174f8f684840b6f8ed0281d5115a748dce924c014daa7
)

renderFromTemplate

Use this function to render an image/pdf.

argumentrequireddescription
templateIdYesID of the template (open-graph-image-1, tweet-image-1, beautify-screenshot-1, ...)
modificationsYesModifications for the selected template.
responseTypeNobase64, binary, url (Defaults to base64).
responseFormatNopng, webp, pdf, jpg, jpeg (Defaults to png).

For available templates and their modifications refer Orshot Templates Page

generateSignedUrl

Use this function to generate signed URL.

keyrequireddescription
templateIdYesID of the template (open-graph-image-1, tweet-image-1, beautify-screenshot-1, ...)
modificationsYesModifications for the selected template.
expiresAtYesExpires at in unix timestamp (Number).
renderTypeNoimages, pdfs (Defaults to images).
responseFormatNopng, webp, pdf, jpg, jpeg (Defaults to png).

On this page