|
| 1 | +# Capture PHP SDK |
| 2 | + |
| 3 | +Official PHP SDK for [Capture](https://capture.page) - Screenshot and content extraction API. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```bash |
| 8 | +composer require techulus/capture |
| 9 | +``` |
| 10 | + |
| 11 | +## Quick Start |
| 12 | + |
| 13 | +```php |
| 14 | +use Techulus\Capture\Capture; |
| 15 | + |
| 16 | +$client = new Capture('your-api-key', 'your-api-secret'); |
| 17 | + |
| 18 | +$imageUrl = $client->buildImageUrl('https://example.com'); |
| 19 | +echo $imageUrl; |
| 20 | +``` |
| 21 | + |
| 22 | +## Features |
| 23 | + |
| 24 | +- **Screenshot Capture**: Capture full-page or viewport screenshots as PNG/JPG |
| 25 | +- **PDF Generation**: Convert web pages to PDF documents |
| 26 | +- **Content Extraction**: Extract HTML and text content from web pages |
| 27 | +- **Metadata Extraction**: Get page metadata (title, description, og tags, etc.) |
| 28 | +- **Animated GIFs**: Create animated GIFs of page interactions |
| 29 | +- **Zero Dependencies**: Uses only PHP built-in extensions (curl, json) |
| 30 | + |
| 31 | +## Usage |
| 32 | + |
| 33 | +### Initialize the Client |
| 34 | + |
| 35 | +```php |
| 36 | +use Techulus\Capture\Capture; |
| 37 | + |
| 38 | +$client = new Capture('your-api-key', 'your-api-secret'); |
| 39 | + |
| 40 | +// Use edge endpoint for faster response times |
| 41 | +$client = new Capture('your-api-key', 'your-api-secret', ['useEdge' => true]); |
| 42 | +``` |
| 43 | + |
| 44 | +### Building URLs |
| 45 | + |
| 46 | +#### Image Capture |
| 47 | + |
| 48 | +```php |
| 49 | +$imageUrl = $client->buildImageUrl('https://example.com'); |
| 50 | + |
| 51 | +$imageUrl = $client->buildImageUrl('https://example.com', [ |
| 52 | + 'full' => true, |
| 53 | + 'delay' => 2, |
| 54 | + 'vw' => 1920, |
| 55 | + 'vh' => 1080, |
| 56 | +]); |
| 57 | +``` |
| 58 | + |
| 59 | +#### PDF Capture |
| 60 | + |
| 61 | +```php |
| 62 | +$pdfUrl = $client->buildPdfUrl('https://example.com'); |
| 63 | + |
| 64 | +$pdfUrl = $client->buildPdfUrl('https://example.com', [ |
| 65 | + 'format' => 'A4', |
| 66 | + 'landscape' => true, |
| 67 | +]); |
| 68 | +``` |
| 69 | + |
| 70 | +#### Content Extraction |
| 71 | + |
| 72 | +```php |
| 73 | +$contentUrl = $client->buildContentUrl('https://example.com'); |
| 74 | +``` |
| 75 | + |
| 76 | +#### Metadata Extraction |
| 77 | + |
| 78 | +```php |
| 79 | +$metadataUrl = $client->buildMetadataUrl('https://example.com'); |
| 80 | +``` |
| 81 | + |
| 82 | +#### Animated GIF |
| 83 | + |
| 84 | +```php |
| 85 | +$animatedUrl = $client->buildAnimatedUrl('https://example.com'); |
| 86 | +``` |
| 87 | + |
| 88 | +### Fetching Data |
| 89 | + |
| 90 | +#### Fetch Image |
| 91 | + |
| 92 | +```php |
| 93 | +$imageData = $client->fetchImage('https://example.com'); |
| 94 | +file_put_contents('screenshot.png', $imageData); |
| 95 | +``` |
| 96 | + |
| 97 | +#### Fetch PDF |
| 98 | + |
| 99 | +```php |
| 100 | +$pdfData = $client->fetchPdf('https://example.com', ['full' => true]); |
| 101 | +file_put_contents('page.pdf', $pdfData); |
| 102 | +``` |
| 103 | + |
| 104 | +#### Fetch Content |
| 105 | + |
| 106 | +```php |
| 107 | +$content = $client->fetchContent('https://example.com'); |
| 108 | +echo $content['html']; |
| 109 | +echo $content['textContent']; |
| 110 | +echo $content['markdown']; |
| 111 | +``` |
| 112 | + |
| 113 | +#### Fetch Metadata |
| 114 | + |
| 115 | +```php |
| 116 | +$metadata = $client->fetchMetadata('https://example.com'); |
| 117 | +print_r($metadata['metadata']); |
| 118 | +``` |
| 119 | + |
| 120 | +#### Fetch Animated GIF |
| 121 | + |
| 122 | +```php |
| 123 | +$gifData = $client->fetchAnimated('https://example.com'); |
| 124 | +file_put_contents('animation.gif', $gifData); |
| 125 | +``` |
| 126 | + |
| 127 | +## Configuration Options |
| 128 | + |
| 129 | +### Constructor Options |
| 130 | + |
| 131 | +- `useEdge` (bool): Use edge.capture.page instead of cdn.capture.page for faster response times |
| 132 | +- `timeout` (int): cURL timeout in seconds. Defaults to `30` |
| 133 | + |
| 134 | +## API Endpoints |
| 135 | + |
| 136 | +The SDK supports two base URLs: |
| 137 | + |
| 138 | +- **CDN**: `https://cdn.capture.page` (default) |
| 139 | +- **Edge**: `https://edge.capture.page` (when `useEdge` is `true`) |
| 140 | + |
| 141 | +## License |
| 142 | + |
| 143 | +MIT |
| 144 | + |
| 145 | +## Links |
| 146 | + |
| 147 | +- [Website](https://capture.page) |
| 148 | +- [Documentation](https://docs.capture.page) |
| 149 | +- [GitHub](https://github.com/techulus/capture-php) |
| 150 | + |
| 151 | +## Support |
| 152 | + |
| 153 | +For support, please visit [capture.page](https://capture.page) or open an issue on GitHub. |
0 commit comments