Skip to content

Commit a1d23da

Browse files
committed
Add initial Capture PHP SDK with tests and CI
0 parents  commit a1d23da

9 files changed

Lines changed: 672 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Tests
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
strategy:
14+
matrix:
15+
php-version: ["8.1", "8.2", "8.3", "8.4"]
16+
17+
steps:
18+
- uses: actions/checkout@v6
19+
20+
- name: Set up PHP ${{ matrix.php-version }}
21+
uses: shivammathur/setup-php@v2
22+
with:
23+
php-version: ${{ matrix.php-version }}
24+
extensions: curl, json
25+
26+
- name: Install dependencies
27+
run: composer install --no-interaction --prefer-dist
28+
29+
- name: Run tests
30+
run: vendor/bin/phpunit

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/
2+
composer.lock
3+
.phpunit.result.cache
4+
.phpunit.cache/

.mise.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[tools]
2+
php = "system"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Techulus
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
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.

composer.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "techulus/capture",
3+
"description": "Official PHP SDK for Capture (capture.page). Capture screenshots, generate PDFs, extract content and metadata from web pages.",
4+
"type": "library",
5+
"license": "MIT",
6+
"keywords": ["capture", "screenshot", "pdf", "web scraping", "content extraction"],
7+
"homepage": "https://capture.page",
8+
"authors": [
9+
{
10+
"name": "Capture Team",
11+
"email": "support@capture.page"
12+
}
13+
],
14+
"require": {
15+
"php": ">=8.1",
16+
"ext-curl": "*",
17+
"ext-json": "*"
18+
},
19+
"require-dev": {
20+
"phpunit/phpunit": "^10.0"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"Techulus\\Capture\\": "src/"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"Techulus\\Capture\\Tests\\": "tests/"
30+
}
31+
}
32+
}

phpunit.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true">
6+
<testsuites>
7+
<testsuite name="Capture SDK Tests">
8+
<directory>tests</directory>
9+
</testsuite>
10+
</testsuites>
11+
</phpunit>

0 commit comments

Comments
 (0)