Hi :)

Is there any way, using PHP, to display a mini-version of an external website ?

What I'm trying to achieve is when my users enter a link, then it should automatically try to display the link's contents - but within a given height / width.

Appriciate any feedback :D

Dani AI

Generated

As hinted, PHP on its own can't render a remote page into a scaled bitmap — you need something that actually renders the page (a browser engine) or you embed the page in the client. Below are practical, long-lived options and quick examples so this thread stays useful years from now.

Client-side (fast, but unreliable for every site)

  • Embed the URL in an iframe and scale it with CSS. Many sites block being framed (X-Frame-Options or CSP frame-ancestors), so this works only for pages that allow embedding.
<div style="width:320px;height:180px;overflow:hidden;">
  <iframe src="https://example.com"
          style="border:0;width:1280px;height:720px;transform:scale(.25);transform-origin:0 0;">
  </iframe>
</div>

This can fail when the target sends X-Frame-Options/CSP. (developer.mozilla.org)

Server-side screenshots (recommended for reliable thumbs)

  • Modern approach: headless Chromium (Puppeteer). From PHP you can either run a Node/Puppeteer service or use a PHP wrapper like Spatie Browsershot to drive Chromium and save an image. Example using Browsershot:
use Spatie\Browsershot\Browsershot;

Browsershot::url('https://example.com')
    ->windowSize(1280,800)
    ->clip(0,0,1280,800)
    ->save('/tmp/thumb.png');

Puppeteer + headless Chrome is the current, robust way to capture modern JS-driven pages. (github.com)

Legacy/lighter-weight option

  • wkhtmltoimage (part of wkhtmltopdf) renders pages using Qt WebKit and is simple to call from PHP with exec(); note it may not handle very modern JS well. Example:
$cmd = '/usr/bin/wkhtmltoimage --quality 75 ' . escapeshellarg($url) . ' /tmp/thumb.png';
exec($cmd, $out, $rc);

Use an image tool (ImageMagick) to resize/crop the result for the exact thumbnail size. (wkhtmltopdf.org)

Tips and cautions

  • Cache every thumbnail; generating images is expensive.
  • Run screenshotting as a worker queue (not during request handling).
  • Set timeouts and limit concurrency; headless browsers need RAM/CPU.
  • Respect site policies — embedding or screenshotting may be blocked by headers or terms.
    These approaches give a reliable thumbnail that fits your width/height constraints while avoiding cross-origin/frame problems.

Recommended Answers

All 4 Replies

No, this is not possible using PHP only.

You could use PHP to call an external program that does this. Also, there are plenty of websites that offer this as a service (paid of course).

No, this is not possible using PHP only.

You could use PHP to call an external program that does this. Also, there are plenty of websites that offer this as a service (paid of course).

Thanks for replying so quick :)

I've been able to open an external website using Curl..but this of course ends up in opening the whole webpage in its full format with html and all unfortunately...

Do you have any examples / links to these external programs you're referring to? Never done anything like this, so I'm somewhat clueless at the moment :)

Would, as far as possible, hopefully be able to create it on my own server rather than user a commercial service from another server.

One example is this one, but this runs on a windows server.

For *nix I just found this description.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.