ThisCalculator

Everyday

Best PHP Packages for URL to Image Conversion

Updated · Standard formula, shown below

Best PHP Packages for URL to Image Conversion

The best overall pick is Browsershot because it wraps Puppeteer to render full, JavaScript-enabled pages into high-fidelity images with minimal PHP code. It handles modern SPAs, lazy-loaded content, and custom viewports better than any pure-PHP alternative, making it the most reliable choice for most teams.

What to Look For

Before choosing a package, weigh these five criteria — they matter more than stars or download counts:

  • JavaScript rendering: If the page uses React, Vue, or lazy-loads images, a pure-PHP solution will capture a blank or partial page. You need a headless browser (Chrome via Puppeteer) for anything beyond static HTML.
  • Output formats: PNG, JPEG, and WebP are common. Some packages also offer PDF, which is handy if you need both image and document output from the same code.
  • Selector-based capture: The ability to screenshot only a specific element (e.g., #chart) rather than the full page saves time and storage.
  • Dependencies and setup: Pure-PHP packages are trivial to install via Composer. Browser-based ones require Node.js and a Chromium binary, which can complicate deployment on shared hosting or locked-down servers.
  • Maintenance and community: A package that hasn’t been updated in years may break with newer PHP or Chrome versions. Check the last release date and open issues before committing.

Browsershot

Strengths: Built on Puppeteer, so it renders pages exactly like Chrome does. You get full JavaScript support, custom viewport sizes, device scale factor, and the ability to wait for network idle or a specific selector before capturing. It outputs PNG, JPEG, WebP, and PDF. The API is clean — a single static call with chained methods.

Trade-offs: Requires Node.js and a Chromium browser on the server. First run downloads Chromium, which can be slow in CI. Shared hosting often doesn’t allow the necessary processes. Also, it’s heavier on memory than pure-PHP options.

Best for: Teams with control over their server environment who need accurate screenshots of modern, JavaScript-heavy sites. Ideal for generating social share images, PDFs, or visual regression tests.

Spatie/Browsershot (the same package — but note the fork)

Strengths: This is the actively maintained fork of the original Browsershot. It adds support for newer Puppeteer versions, better error handling, and a more consistent API. It’s the version most tutorials now reference.

Trade-offs: Same Node/Chrome requirement as above. Also, because it’s a fork, some older documentation may not match exactly — check the README for the current method names.

Best for: Anyone who wants the Browsershot experience but with recent bug fixes and ongoing support. If you’re starting fresh, use this fork.

PHP Screenshot (php-screenshot/php-screenshot)

Strengths: A pure-PHP package that uses a headless Chrome via the Chrome DevTools Protocol directly — no Node.js needed. It’s lighter than Browsershot and can be installed with just Composer and a Chrome/Chromium binary. It supports full-page and element screenshots, and it’s quite fast for simple pages.

Trade-offs: Still requires Chrome to be installed on the server. The API is lower-level than Browsershot, so you’ll write more code for advanced features like waiting for network requests. Documentation is thinner, and the community is smaller.

Best for: PHP developers who want to avoid Node.js but still need real browser rendering. Good for internal tools or simple report generation.

Goutte + DomDocument (pure PHP, no browser)

Strengths: Goutte is a web scraper that fetches HTML and parses it with Symfony DomCrawler. Combined with a simple image creation library like GD or Imagick, you can build a basic “screenshot” by rendering text and images manually. It’s extremely lightweight, has zero external dependencies beyond PHP extensions, and works on any shared host.

Trade-offs: It does not execute JavaScript, so any dynamic content will be missing. You’ll need to write your own layout logic to position text and images — it’s not a true screenshot. The result will look nothing like the actual page unless you invest significant effort.

Best for: Very simple use cases like generating a thumbnail with a page title and URL, where a real screenshot is overkill. Not recommended for anything that needs to match the actual page.

PhantomJS (via PHP wrappers like JonnyW/PhantomJs)

Strengths: PhantomJS was the go-to headless browser before Chrome’s headless mode matured. PHP wrappers like jonnyw/php-phantomjs let you drive it from PHP. It supports JavaScript and can produce screenshots.

Trade-offs: PhantomJS is no longer maintained — the project was archived in 2018. It lacks support for modern JavaScript features (ES6+, some CSS), and it’s increasingly difficult to install on newer systems. Security vulnerabilities may exist.

Best for: Legacy projects that already use PhantomJS and cannot migrate immediately. For new projects, avoid it.

Headless Chrome via Symfony Process (DIY)

Strengths: You can write a small PHP class that uses Symfony Process to run google-chrome --headless --screenshot=output.png URL. This gives you full control, no package dependencies, and it’s surprisingly simple for basic screenshots. Chrome’s headless mode is fast and reliable.

Trade-offs: You have to handle process management, error checking, and file naming yourself. Advanced features like waiting for a specific element require more complex command-line flags or a DevTools protocol client. It’s not a ready-made package, so you’ll maintain more code.

Best for: Developers who need a quick, no-dependency solution and are comfortable writing a few dozen lines of shell-command wrapper code.

How to Choose

Start with your budget and hosting. If you’re on a shared host that doesn’t allow Node.js or long-running processes, Browsershot is out. In that case, you’ll need a pure-PHP approach (Goutte) or you’ll need to move to a VPS or cloud function that can run Chrome.

Next, consider your use case. For generating social media cards from blog posts, you need full JS rendering — Browsershot is the clear winner. For simple URL previews (like a link thumbnail), a pure-PHP scraper that extracts the title and meta description might be enough, and it will be much faster and cheaper.

Also think about volume. If you’re converting thousands of URLs per day, a headless browser per request will be slow and resource-hungry. You might want to queue the jobs and use a service like Puppeteer on a separate worker, or consider a cloud API (like Urlbox or ScreenshotOne) that handles the rendering for you — though that adds a recurring cost.

Finally, weigh maintenance. Browsershot is actively maintained and has a large community. PHP Screenshot is smaller but still updated. PhantomJS is dead — avoid it. If you go DIY, you own the maintenance burden.

Frequently Asked Questions

Do I need Node.js to use Browsershot?
Yes, Browsershot requires Node.js to run Puppeteer. The package installs Puppeteer via npm, and that downloads Chromium. You can avoid Node.js by using PHP Screenshot or the DIY approach.

Can I capture only a part of the page?
Yes, Browsershot and PHP Screenshot both support element selectors. You can screenshot a specific div or #id. The DIY Chrome command-line method also supports --window-size but not element selection without extra scripting.

What about pages that require login?
You can pass cookies or authentication headers in Browsershot and PHP Screenshot. For a DIY approach, you’d need to use Chrome’s remote debugging protocol to set cookies, which is more complex.

Is it possible to convert a URL to a PDF too?
Yes, Browsershot supports PDF output. PHP Screenshot also has a PDF mode. Pure-PHP solutions do not.

How fast is URL-to-image conversion?
It depends on the page. A simple static page might take 1-2 seconds with a headless browser; a heavy SPA could take 5-10 seconds. Pure-PHP scraping is faster (under a second) but produces a non-visual result.

Can I run this on a cron job?
Yes, all these packages work in CLI scripts. Just be careful with memory limits and ensure the Chrome process is properly killed after each run. Browsershot has a timeout() method to avoid hanging.

Bottom Line

For the vast majority of use cases, Browsershot (the Spatie fork) is the best choice — it’s reliable, feature-rich, and actively maintained. If you absolutely cannot install Node.js, use PHP Screenshot as a close second. Avoid PhantomJS entirely, and only consider Goutte if you need a quick, non-visual thumbnail. For high-volume or low-maintenance needs, a cloud screenshot API might be worth the cost, but for most projects, Browsershot gives the best balance of power and simplicity.

Related

Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.