1. Go to this page and download the library: Download sunergos/og-pilot-php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Sunergos\OgPilot\Facades\OgPilot;
// Generate an image URL
$imageUrl = OgPilot::createImage([
'template' => 'blog_post',
'title' => 'How to Build Amazing OG Images',
'description' => 'A complete guide to social media previews',
'bg_color' => '#1a1a1a',
'text_color' => '#ffffff',
'author_name' => 'Jane Smith',
'publish_date' => '2024-01-15',
]);
// With cache refresh (using iat)
$imageUrl = OgPilot::createImage([
'template' => 'blog_post',
'title' => 'My Blog Post',
], [
'iat' => time(), // Refresh cache daily
]);
// Get JSON metadata instead
$data = OgPilot::createImage([
'template' => 'page',
'title' => 'Hello OG Pilot',
], [
'json' => true,
]);
use Sunergos\OgPilot\OgPilot;
// Configure once at application bootstrap
OgPilot::setConfig([
'api_key' => 'your-api-key',
'domain' => 'your-domain.com',
'image_type' => 'webp',
'quality' => 82,
'max_bytes' => 220000,
]);
// Generate an image URL
$imageUrl = OgPilot::createImage([
'template' => 'blog_post',
'title' => 'How to Build Amazing OG Images',
]);
// Or use the callback-style configuration
OgPilot::configure(function ($config) {
$config->apiKey = 'your-api-key';
$config->domain = 'your-domain.com';
});
use Sunergos\OgPilot\OgPilot;
use Sunergos\OgPilot\Client;
// Using the factory method
$client = OgPilot::createClient([
'api_key' => 'your-api-key',
'domain' => 'your-domain.com',
'connect_timeout' => 3.0,
'timeout' => 8.0,
'image_type' => 'webp',
'quality' => 82,
'max_bytes' => 220000,
]);
$url = $client->createImage(['title' => 'Hello']);
// Or instantiate directly
$client = new Client([
'api_key' => 'your-api-key',
'domain' => 'your-domain.com',
'image_type' => 'webp',
]);
$imageUrl = OgPilot::createBlogPostImage([
'title' => 'How to Build Amazing OG Images',
'author_name' => 'Jane Smith',
'publish_date' => '2024-01-15',
]);
use Sunergos\OgPilot\Facades\OgPilot;
// In a controller, view, or anywhere in your Laravel app
$imageUrl = OgPilot::createImage([
'template' => 'blog_post',
'title' => 'My Blog Post',
]);
// path is automatically captured from the current request
use Sunergos\OgPilot\OgPilot;
// At the start of your request handling
OgPilot::setCurrentRequest([
'url' => $_SERVER['REQUEST_URI'] ?? '/'
]);
// Your application code...
$imageUrl = OgPilot::createImage(['title' => 'My Page']);
// path is automatically set from REQUEST_URI
// At the end of your request
OgPilot::clearCurrentRequest();
use Sunergos\OgPilot\OgPilot;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class OgPilotListener
{
public function onKernelRequest(RequestEvent $event): void
{
$request = $event->getRequest();
OgPilot::setCurrentRequest([
'path' => $request->getRequestUri()
]);
}
}