Hi All,

I am making a web directory in which i have one field of url of website which is i am taking form a form. Now i want to do this when i will show this url on my site then this will fetch screenshot of that url on my site.

How i can do this using PHP code. Please help me to do so. I will be very appreciate of that person.

Thanks

Dani AI

Generated

asked how to show a screenshot for each URL in a directory. Clarifying the thread: ’s onmouseover idea gives a client-side preview only (no server-side image file to cache or serve later), while correctly pointed out that ready-made thumbnail generators exist. For a durable, cacheable thumbnail (visible even when the remote site is slow or down) a server-side capture or a hosted screenshot API is the right approach.

Three practical options to consider:

  • Hosted screenshot APIs: easiest to integrate (send URL, receive image) but can cost money and impose rate limits.
  • Self-hosted capture with a headless browser: recommended for modern, JS-heavy sites — run headless Chrome/Chromium (Puppeteer or CLI) from the server, or use a simpler binary like wkhtmltoimage for static pages. Produce a PNG, then resize with ImageMagick or GD.
  • Prebuilt PHP thumbnail scripts: good tradeoff if maintenance burden and features match the project (faster to get started).

Minimal implementation notes and a small example call (server must permit exec):

$cmd = '/usr/bin/wkhtmltoimage --width 1024 ' . escapeshellarg($url) . ' ' . escapeshellarg($out);
exec($cmd, $lines, $ret);

Operational and security tips: validate URLs with filter_var(..., FILTER_VALIDATE_URL) and parse_url, implement a host-allowlist and block private IP ranges to avoid SSRF, run captures in a sandbox/container with strict timeouts and limited privileges, cache thumbnails and generate them at submission time or via a background queue to avoid slow page loads, and use a placeholder when capture fails. For JS-heavy sites prefer headless Chrome with a short wait-for-network-idle or fixed delay; set viewport and device scale factor if HiDPI screenshots are needed. Finally, respect robots/copyright and consider rate limits when capturing many external sites.

Recommended Answers

All 2 Replies

without having the exact code at hand id say you will need to use javascript in your href using the onmouseover function.

here is some good information on it

to display the page should just be a case of having that javascript containing the URL of that paticular page

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.