Skip to content

How to make screenshots in PHP

Capture a web page from PHP by sending a cURL request to a screenshot API and saving the returned PNG.

OUTPUT FORMATSHTMLJSONMarkdown

Choose between a viewport image, a full-page image, or a single element, then adjust the viewport size when the visible area needs to change.

Start with the capture type you need

A PHP script can request a rendered page image through an API call made with cURL. The response is image data that the script writes to a PNG file. Three request parameters cover the main capture choices: screenshot for the viewport, screenshot_full_page for the whole rendered page, and screenshot_selector for one element. The API also handles proxy rotation and JavaScript rendering, which helps scripts work on complex sites without building that infrastructure in PHP.

Viewport screenshots and custom size

Use screenshot when only what is visible without scrolling matters. Set it to true and pass the target URL and API key. The default viewport is 1920 by 1080 pixels. If that framing is too wide or too tall, add window_width and window_height. For example, 1280 by 620 produces a smaller viewport image of the same blog page used in the worked example. The protected PHP module code0001 shows the basic cURL request, query building, error handling, status output, and PNG save flow.

Full-page screenshots

Choose screenshot_full_page when content below the fold must be included. Setting it to true returns a tall image covering the entire rendered page, including sections that require scrolling to see in a browser. This is the right choice for archiving a complete page layout, while the viewport option is better for a compact preview or a first-screen check.

Element screenshots

Use screenshot_selector to isolate one part of a page. Passing footer captures the footer element, and the same approach can target a header or another element by its selector. This avoids cropping a larger image afterward and keeps the file focused on the component being reviewed or archived.

Quick checklist

Before running a script, confirm the target URL, API key, capture parameter, and output filename. After the request, check the HTTP status code and whether the response was received before writing the file. If the request fails, surface the cURL error and error code rather than saving an empty image. Each method returns a PNG that can be saved directly.

Which screenshot parameter should you use?
Capture parameterWhat it returnsUse it when
screenshotVisible viewport onlyYou need the first-screen view
window_width / window_heightResized viewport framingThe default 1920 by 1080 viewport does not fit the task
screenshot_full_pageEntire rendered page, including below-the-fold contentYou need a complete page archive
screenshot_selectorOne specified page element, such as footerYou need only a header, footer, or other component

Parameters are set in the API request alongside the target URL and API key.