PHP code example of techulus / capture

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

    

techulus / capture example snippets


use Techulus\Capture\Capture;

$client = new Capture('your-api-key', 'your-api-secret');

$imageUrl = $client->buildImageUrl('https://example.com');
echo $imageUrl;

use Techulus\Capture\Capture;

$client = new Capture('your-api-key', 'your-api-secret');

// Use edge endpoint for faster response times
$client = new Capture('your-api-key', 'your-api-secret', ['useEdge' => true]);

$imageUrl = $client->buildImageUrl('https://example.com');

$imageUrl = $client->buildImageUrl('https://example.com', [
    'full' => true,
    'delay' => 2,
    'vw' => 1920,
    'vh' => 1080,
]);

$pdfUrl = $client->buildPdfUrl('https://example.com');

$pdfUrl = $client->buildPdfUrl('https://example.com', [
    'format' => 'A4',
    'landscape' => true,
]);

$contentUrl = $client->buildContentUrl('https://example.com');

$metadataUrl = $client->buildMetadataUrl('https://example.com');

$animatedUrl = $client->buildAnimatedUrl('https://example.com');

$imageData = $client->fetchImage('https://example.com');
file_put_contents('screenshot.png', $imageData);

$pdfData = $client->fetchPdf('https://example.com', ['full' => true]);
file_put_contents('page.pdf', $pdfData);

$content = $client->fetchContent('https://example.com');
echo $content['html'];
echo $content['textContent'];
echo $content['markdown'];

$metadata = $client->fetchMetadata('https://example.com');
print_r($metadata['metadata']);

$gifData = $client->fetchAnimated('https://example.com');
file_put_contents('animation.gif', $gifData);

$session = $client->sessions()->create(['maxTtlSeconds' => 300]);
$sessionId = $session['session']['id'];

$client->sessions()->action($sessionId, 'goto', ['url' => 'https://example.com']);
$screenshot = $client->sessions()->action($sessionId, 'screenshot', ['fullPage' => true]);

$client->sessions()->close($sessionId);

$created = $client->sessions()->create([
    'maxTtlSeconds' => 300,
    'cdp' => true,
]);

$session = $created['session'];
$connectUrl = $session['connectUrl'];

echo $connectUrl;

$client->sessions()->close($session['id']);