Capture Image Screenshots with PHP

Since PHP 5.2.2 it is now possible to capture a website or any window’s screenshot to an image with PHP as long as it is running on a Window’s machine. Most web-servers are running Linux but this could be useful for a tool on your home Dev server.

Capture Whole Screen

<?php
$img = imagegrabscreen();
imagepng($img, 'screenshot.png');
?>

Capture an Application’s Window

<?php
$Browser = new COM('InternetExplorer.Application');
$Browserhandle = $Browser->HWND;
$Browser->Visible = true;
$Browser->Fullscreen = true;
$Browser->Navigate('http://www.stackoverflow.com');
 
while($Browser->Busy){
  com_message_pump(4000);
}
 
$img = imagegrabwindow($Browserhandle, 0);
$Browser->Quit();
imagepng($img, 'screenshot.png');
?>
affiliate_link
Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Comments are closed.