Take a screenshot of a website

how to take a screenshot of a website in php , then saving it to a file. like this site www.retailmenot.com the screenshots are under “Today’s Top Coupons” part.Thanks. what ways of publishing the website’s screenshot it uses?

Quite likely the company would use a service, such as www.thumbshots.com, to provide the screenshots for them.

PHP itself isn’t able to take “screenshots” of websites.

I belive this code that has been posted at least twice before will work on a windows server. It will on my XAMPP Vista setup anyway:

$browser = new COM("InternetExplorer.Application");
$handle = $browser->HWND;
$browser->Visible = true;
// Still working?
while ($browser->Busy) {com_message_pump(4000);
}$im = imagegrabwindow($handle, 0);
imagepng($im, "iesnap.png");

If you setup an X Server ? or whatever it is you can use Imagemagick.

I belive there is a program htmltopdf or something that you can use but that may need an xserver as well.

The simplest way would be to use another online service as pmw57 said unless you have or want to change to a Windows server - check it will work before splashing out on a different server !

rubble, i have tested your code in my local enviroment by IE, where is the screeshot in?

The screenshot should be in the same folder as the code and called iesnap.png

Hi Rubble,

Thanks for helping out, I’m sure runeveryday has similar sentiments. :wink:


wkhtmltoimage is worth a look if you have command line access on a linux server

oh, got it. but my iesnap.png is a black image, there is no any picture on the image.

ps:if i want to put the image in a file, how should i do? thank you,

The first line is the browser to use - do you have internet explorer installed? Thats the only thing I can think of why it will not work.

There are different ways of getting it in a file; if its the same image just retaken say once a day/week/whatever I would always call it the same name and it will overwrite the previouse image.
You could call the image something descriptive e.g. google.jpg, yahoo.jpg etc. and setup some code that reads the directory for all the jpg images and create the pages then inserts the image onto the page.