PHP code example of toolcenter / sdk

1. Go to this page and download the library: Download toolcenter/sdk 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/ */

    

toolcenter / sdk example snippets




oolCenter\ToolCenter;

// Initialize the client with your API key
$tc = new ToolCenter('your-api-key-here');

// Capture a screenshot
$screenshot = $tc->screenshot([
    'url' => 'https://example.com',
    'width' => 1920,
    'height' => 1080,
    'format' => 'png'
]);

echo "Screenshot URL: " . $screenshot['url'] . "\n";

$tc = new ToolCenter('your-api-key-here');

// Or with a custom base URL
$tc = new ToolCenter('your-api-key-here', 'https://custom.toolcenter.dev');

// Basic screenshot
$result = $tc->screenshot([
    'url' => 'https://example.com'
]);

// Full page screenshot with custom dimensions
$result = $tc->screenshot([
    'url' => 'https://example.com',
    'width' => 1920,
    'height' => 1080,
    'fullPage' => true,
    'format' => 'webp',
    'quality' => 90
]);

// Generate PDF
$result = $tc->pdf([
    'url' => 'https://example.com',
    'format' => 'A4',
    'orientation' => 'portrait',
    'margin' => '1cm'
]);

// PDF with custom options
$result = $tc->pdf([
    'url' => 'https://example.com',
    'format' => 'letter',
    'landscape' => true,
    'printBackground' => true,
    'scale' => 0.8
]);

// Simple QR code
$result = $tc->qr([
    'data' => 'https://toolcenter.dev',
    'size' => 300
]);

// Customized QR code
$result = $tc->qr([
    'data' => 'Hello World!',
    'size' => 500,
    'format' => 'svg',
    'errorCorrection' => 'M',
    'margin' => 4
]);

// Extract website metadata
$result = $tc->metadata([
    'url' => 'https://example.com'
]);

// Include images and social media data
$result = $tc->metadata([
    'url' => 'https://example.com',
    '

// Bulk screenshots
$urls = [
    'https://example.com',
    'https://google.com',
    'https://github.com'
];

$results = $tc->bulkScreenshot($urls);

// Bulk PDFs
$results = $tc->bulkPdf($urls);

// Bulk metadata
$results = $tc->bulkMetadata($urls);



namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use ToolCenter\ToolCenter;

class ToolCenterServiceProvider extends ServiceProvider
{
    public function register()
    {
        $this->app->singleton(ToolCenter::class, function ($app) {
            return new ToolCenter(config('services.toolcenter.api_key'));
        });
    }
}

'toolcenter' => [
    'api_key' => env('TOOLCENTER_API_KEY'),
],



namespace App\Http\Controllers;

use ToolCenter\ToolCenter;

class ScreenshotController extends Controller
{
    public function __construct(private ToolCenter $toolCenter)
    {
    }

    public function capture(Request $request)
    {
        $screenshot = $this->toolCenter->screenshot([
            'url' => $request->input('url'),
            'width' => 1920,
            'height' => 1080
        ]);

        return response()->json($screenshot);
    }
}

use ToolCenter\Exceptions\ToolCenterException;
use ToolCenter\Exceptions\AuthenticationException;
use ToolCenter\Exceptions\RateLimitException;

try {
    $result = $tc->screenshot(['url' => 'https://example.com']);
} catch (AuthenticationException $e) {
    // Handle authentication errors (401)
    echo "Authentication failed: " . $e->getMessage();
} catch (RateLimitException $e) {
    // Handle rate limit errors (429)
    echo "Rate limit exceeded: " . $e->getMessage();
} catch (ToolCenterException $e) {
    // Handle other API errors
    echo "API error: " . $e->getMessage();
    
    // Get the full response for debugging
    $response = $e->getResponse();
    print_r($response);
}