From 7360d0b08a013b6cf7664ac4dbc405890b17f6fd Mon Sep 17 00:00:00 2001 From: Chris Date: Fri, 24 Apr 2026 15:43:08 +0200 Subject: [PATCH] feat: add fullpage and maxheight parameters for enhanced screenshot options --- CLAUDE.md | 2 +- README.md | 37 +++++++++++++++++++++++++++++------- src/templates/index.html.php | 12 ++++++++++++ web/index.php | 26 +++++++++++++++++++++++-- 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/CLAUDE.md b/CLAUDE.md index 4928d5a..1da89a5 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -9,7 +9,7 @@ http2pic - PHP website renderer that takes screenshots of URLs and returns them ## Architecture **Entry point:** `web/index.php` - PSR-4 router with two paths: -- `/api` - Chrome/Chromium screenshot via Selenium WebDriver (php-webdriver). Takes `url`, `viewport` (WIDTHxHEIGHT), `js` (true/false) params. Connects to `localhost:4444` ChromeDriver, sets window size, disables scrollbars, takes screenshot as PNG. +- `/api` - Chrome/Chromium screenshot via Selenium WebDriver (php-webdriver). Params: `url`, `viewport` (WIDTHxHEIGHT), `js` (true/false), `fullpage` (true/false), `maxheight` (1–30000, default 15000). Connects to `localhost:4444` ChromeDriver, sets window size, takes screenshot as PNG. In fullpage mode, resizes window to full `scrollHeight` (capped at `maxheight`) instead of hiding overflow. - default - renders `src/templates/index.html.php` (landing page). **Legacy class:** `src/http2pic.class.php` - Old `wkhtmltoimage`-based renderer (deprecated, not used in production). Supports PNG/JPG, viewport, resize, URL reachability check, file caching. diff --git a/README.md b/README.md index 0d4a273..4ca93a3 100755 --- a/README.md +++ b/README.md @@ -28,18 +28,41 @@ Whenever you come to this page you can just [download](https://github.com/chrisi ## Usage -After you extracted the contents of this repo to your webserver and can access the page and it will tell you how to use the API. - -But it's as simple as: - ``` -https://your-url-and.path/api.php?[OPTIONS]&url=[WEBSITE_URL] +https://your-host/api?url=[WEBSITE_URL]&[OPTIONS] ``` -The requested page will render as image (not provide a link). So you can use the path to your api.php file like so: +### Parameters + +| Parameter | Default | Description | +|-----------|---------|-------------| +| `url` | — | Target URL to screenshot (required) | +| `viewport` | `1024x768` | Viewport size as `WIDTHxHEIGHT` (max 3840x2160) | +| `js` | `true` | Enable JavaScript (`true`/`false`) | +| `fullpage` | `false` | Capture full page height instead of viewport only | +| `maxheight` | `15000` | Max pixel height for full-page captures (1–30000) | +| `key` | — | API key (if `API_KEY` env var is set) | + +### Examples + +```bash +# Standard viewport screenshot +curl "https://your-host/api?url=https://example.com" -o screenshot.png + +# Full-page screenshot (great for LLM analysis) +curl "https://your-host/api?url=https://example.com&fullpage=true" -o full.png + +# Full-page with custom width and height cap +curl "https://your-host/api?url=https://example.com&fullpage=true&viewport=1280x768&maxheight=20000" -o full.png + +# With API key +curl -H "X-API-Key: your-secret" "https://your-host/api?url=https://example.com&fullpage=true" -o full.png +``` + +Use as an `` src: ```html - + ``` ### Example php script to proxy an image to the local server diff --git a/src/templates/index.html.php b/src/templates/index.html.php index 77fb841..a4ef4f0 100755 --- a/src/templates/index.html.php +++ b/src/templates/index.html.php @@ -102,6 +102,18 @@ Allows you to enable/disable JavaScript in the rendered Website. Default value: yes js=false + + fullpage + true|false + Capture the full page height instead of just the viewport. Useful for long pages and LLM analysis. Default: false + fullpage=true + + + maxheight + 1–30000 + Maximum pixel height when using fullpage=true. Default: 15000 + maxheight=20000 + diff --git a/web/index.php b/web/index.php index 514cf8d..f236b4d 100755 --- a/web/index.php +++ b/web/index.php @@ -63,6 +63,18 @@ switch ($url[0]) { $js = $_REQUEST['js'] == 'false' ? false : true; + $fullpage = isset($_REQUEST['fullpage']) && $_REQUEST['fullpage'] === 'true'; + $maxheight = 15000; + if (isset($_REQUEST['maxheight'])) { + $mh = intval($_REQUEST['maxheight']); + if ($mh < 1 || $mh > 30000) { + header('HTTP/1.0 400 Bad Request'); + echo 'maxheight must be between 1 and 30000'; + exit; + } + $maxheight = $mh; + } + if (defined('BLOCK_PRIVATE_IPS') && BLOCK_PRIVATE_IPS) { $host = parse_url($target, PHP_URL_HOST); if (filter_var($host, FILTER_VALIDATE_IP)) { @@ -98,9 +110,19 @@ switch ($url[0]) { $driver = RemoteWebDriver::create($serverUrl, $capabilities, 30000, 60000); $driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($vpParts[0], $vpParts[1])); $driver->get($target); - $driver->executeScript('document.body.style.overflow = "hidden";'); - addToLog($ip . ' Requested ' . $target . ' viewport=' . $viewport . ' js=' . ($js ? 'enabled' : 'disabled')); + if ($fullpage) { + $fullH = (int)$driver->executeScript('return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)'); + $cappedH = min($fullH, $maxheight); + if ($cappedH < $fullH) { + addToLog($ip . ' Full-page height capped at ' . $maxheight . 'px (actual: ' . $fullH . 'px) for ' . $target); + } + $driver->manage()->window()->setSize(new \Facebook\WebDriver\WebDriverDimension($vpParts[0], $cappedH)); + } else { + $driver->executeScript('document.body.style.overflow = "hidden";'); + } + + addToLog($ip . ' Requested ' . $target . ' viewport=' . $viewport . ' js=' . ($js ? 'enabled' : 'disabled') . ($fullpage ? ' fullpage=true' : '')); $screenshot = $driver->takeScreenshot(); header('Content-Type: image/png');