creating an php screenshot application is not an easy task. for that you must have dedicated application or you must use services provided by another providers.
I don't know that it would be impossible with PHP, certainly not if it could call on an external program. I mean, you only have to use curl to get the html source, then convert the html to image before resizing it with gd library. If you could write a command line program (or if one exists) to convert html to jpg your laughing.
I've been tinkering with this idea myself and wrote this but after writing it I contact the service provider and they told me I could not use it it was basically a webservice that showed you your page in IE7 and I thought I would be a smart ass and grab the images and shrink them to thumbnail size. I guess I should get permission first back to the drawing board I was thinking of getting the html for the page and then getting the stylesheet pregmatch all the div's with the ones on the stylesheet and then using gd to render the appropriate sizes and for the dives and a couple of switch casses for if a div is in a div or span basically every webpage start with the either the html size, body size or a container size of some sortlike if you have float:left; and capture all the attributes for that div get the width limits by the containing div if the width is the same than on if another occurence of the div shows up than move said div down if the containing box is is less than the div's I'll let you know how much it is worth when I am done. kidding of course os
andy peters can i just say you have the best name/emoticon combo i have seen on dp....lol I have got imagegrabwindow and imagegrabscreen working - they are slow but useful
It's buggy, it's restrictive, and limited to certain systems. Oh, and some of the code is weird. But it works, for me. http://danltn.com/bin/8g9.phps Windows, PHP 5.2.2+ only, GD Lib, Working IE with desktop access. (Yeah, I'll finish it when my exams are over.) <?php /** * Danltn | http://danltn.com/ * MSN: msn[at]danltn.com * Email: daniel[at]neville.tk * Tested: Yes * Extra Details: Buggy * PHP 4/5: 5.2.2+ * No warranty is given to code used. AT ALL. I MEAN IT! USE IT AT YOUR OWN RISK! */ set_time_limit(120); class screenshot { protected $started = false; public static $image = null; public $details = array(); public $pagecontent = false; public static $manipulate; protected $IE = null; protected $url = false; protected static $instance; protected $visible = false; protected $fullscreen = false; protected $height = false; protected $width = false; protected $silent = false; protected $status_bar = false; protected $address_bar = false; protected $top = false; protected $left = false; protected $resizable = false; protected $theatermode = false; protected $toolbar = false; public $pump = false; public function __construct($pump = false, $width = false, $height = false) { $this->started = true; $this->check_compatibility() or die($this->error('PHP too old or functions missing!')); register_shutdown_function(array(&$this, "__destruct")); $this->start_ie(); $this->set_visible(true); $this->size($height, $width); if ($pump) { $this->pump = true; } return $this; } public function manipulate($image = null) { $this->manipulate = new manipulate($image); return $this; } public function manipulate_end($image = null) { if ($image) { $this->image = $image; } $this->manipulate = null; unset($this->manipulate); } public function getimage() { return ($this->image) ? $this->image : false; } public function navigate($url = 'about:blank') { $url = ($url) ? $url : 'about:blank'; $this->IE->Navigate(($url) ? $url : 'about:blank'); $this->url = $url; $time = time(); while ($this->IE->ReadyState != '4' and $time + 10 > time()) { $this->pump(); } if ($this->pump) { $this->pump(1000); } } public function silent($silent = true) { if ($silent == SWAP) { $this->IE->Silent = !$this->silent; $this->silent = !$this->silent; } else { $this->IE->Silent = (bool)$silent; $this->silent = (bool)$silent; } if ($this->pump) { $this->pump(); } return $this; } public function get_handle() { return $this->IE->HWND; } private function check_compatibility() { if (version_compare(phpversion(), "5.2.2", "<")) { $this->error('PHP Version too old, 5.2.2 required.', 1); return false; } if (!function_exists('imagegrabwindow') or !function_exists('com_message_pump') or !function_exists('imagepng') or !class_exists('COM')) { $this->error('Required PHP functions missing.', 1); return false; } return true; } public function start_ie() { $this->IE = new COM("InternetExplorer.Application") or die($this->error('Could not start Internet Explorer instance.')); if ($this->pump) { $this->pump(); } return $this; } public function quit() { if (isset($this->IE)) { if (is_object($this->IE)) { $this->IE->Quit(); } $this->IE = null; unset($this->IE); } return $this; } public function details() { $this->details['path'] = $this->IE->Path; $this->details['fullname'] = $this->IE->FullName; $this->details['name'] = $this->IE->Name; $this->details['offline'] = $this->IE->Offline; return $this; } public function set_visible($visible = true) { if ($visible == SWAP) { $this->IE->Visible = !$this->visible; $this->visible = !$this->visible; } else { $this->IE->Visible = (bool)$visible; $this->visible = (bool)$visible; } if ($this->pump) { $this->pump(); } return $this; } public function set_resizable($resizable = true) { if ($resizable == SWAP) { $this->IE->Resizable = !$this->resizable; $this->resizable = !$this->resizable; } else { $this->IE->Resizable = (bool)$resizable; $this->resizable = (bool)$resizable; } if ($this->pump) { $this->pump(); } return $this; } public function status_bar($status_bar = false) { if ($status_bar == SWAP) { $this->IE->StatusBar = !$this->status_bar; $this->status_bar = !$this->status_bar; } else { $this->IE->StatusBar = (bool)$status_bar; $this->status_bar = (bool)$status_bar; } if ($this->pump) { $this->pump(); } return $this; } public function address_bar($address_bar = false) { if ($address_bar == SWAP) { $this->IE->AddressBar = !$this->address_bar; $this->address_bar = !$this->address_bar; } else { $this->IE->AddressBar = (bool)$address_bar; $this->address_bar = (bool)$address_bar; } if ($this->pump) { $this->pump(); } return $this; } public function set_fullscreen($fullscreen = true) { if ($fullscreen == SWAP) { $this->IE->Fullscreen = !$this->fullscreen; $this->fullscreen = !$this->fullscreen; } else { $this->IE->Fullscreen = (bool)$fullscreen; $this->fullscreen = (bool)$fullscreen; } if ($this->pump) { $this->pump(); } return $this; } public function set_toolbar($toolbar = true) { if ($toolbar == SWAP) { $this->IE->ToolBar = !$this->toolbar; $this->toolbar = !$this->toolbar; } else { $this->IE->ToolBar = (bool)$toolbar; $this->toolbar = (bool)$toolbar; } if ($this->pump) { $this->pump(); } return $this; } public function go($where = '', $times = 1) { $where = ucfirst(strtolower(($where))); if (!in_array($where, array('Home', 'Back', 'Forward'))) { $where = 'Back'; } $do = 'Go' . $where; for ($i = 0; $i < $times; $i++) { $this->IE->$do(); } } public function document($element, $set) { eval('$this->IE->document->' . $element . ' = $set;'); /* I hate eval too, but I couldn't think of another way of doing this without going into a ridiculous loop, any ideas? */ return $this; } public function body($element, $set) { eval('$this->IE->document->body->' . $element . ' = $set;'); /* I hate eval too, as above */ return $this; } public function set_theatermode($theatermode = true) { if ($theatermode == SWAP) { $this->IE->TheaterMode = !$this->theatermode; $this->theatermode = !$this->theatermode; } else { $this->IE->TheaterMode = (bool)$theatermode; $this->theatermode = (bool)$theatermode; } if ($this->pump) { $this->pump(); } return $this; } public function title($title) { $this->IE->document->title = $title; return $this; } public function content($content) { $this->IE->document->body->InnerHTML = $content; return $this; } public function size($height = false, $width = false) { if (!$height and !$this->height) { $this->height = 600; $this->IE->Height = 600; } elseif ($height) { $this->height = intval($height); $this->IE->Height = intval($height); } if (!$width and !$this->width) { $this->width = 600; $this->IE->Width = 600; } elseif ($width) { $this->width = intval($width); $this->IE->Width = intval($width); } if ($this->pump) { $this->pump(); } return $this; } public function position($top = false, $left = false) { if (!$left and !$this->left) { $this->left = 100; $this->IE->Left = 100; } elseif ($left) { $this->left = intval($left); $this->IE->Left = intval($left); } if (!$top and !$this->top) { $this->top = 100; $this->IE->Top = 100; } elseif ($top) { $this->top = intval($top); $this->IE->Top = intval($top); } if ($this->pump) { $this->pump(); } return $this; } private function error($errmsg = '', $die = 0) { if (!$errmsg) { $errmsg = 'An unspecified error occured.'; } echo '<h1>Error</h1><h2>' . $errmsg . '</h2>'; if ($die) die(); return false; } public function pump($time = 100, $force = 0) { if ($force == 1) { com_message_pump(intval($time)); } while ($this->IE->Busy) { com_message_pump(intval($time)); } } public function capture($what = WINDOW) { if (!$this->visible) { $this->set_visible(true); $reset_visible = true; } $this->image = null; $this->pump(500); $function = 'imagegrab' . (($what == 3 or strtolower($what) == 'screen') ? 'screen' : 'window'); $im = $function($this->IE->HWND, 0); $this->image = $im; if (isset($reset_visible)) { $this->set_visible(false); } return $this; } public function output($imagetype = 'png') { if (!$this->image) { $this->capture(); } if ($imagetype == 'jpg') { $imagetype = 'jpeg'; } if (!in_array($imagetype, array('jpeg', 'gif', 'png'))) { $imagetype = 'png'; /* We know this one works */ } $function = 'image' . $imagetype; header('Content-type: image/' . $imagetype); $function($this->image); } public function __toString() { if ($this->image) { echo $this->image; } elseif ($this->url) { echo $this->url; } else { echo ''; } return $this; } public function save($file, $imagetype = 'png') { if (!$this->image) { $this->capture(); } if ($imagetype == 'jpg') { $imagetype = 'jpeg'; } if (!in_array($imagetype, array('jpeg', 'gif', 'png'))) { $imagetype = 'png'; /* We know this one works */ } $function = 'image' . $imagetype; $function($this->image, $file); } final public static function getInstance() { if (!isset(self::$instance)) { $c = __class__; $instance = new $c; } return self::$instance; } public function __destruct() { $this->quit(); } } class manipulate extends screenshot { public $nimage; public function __construct($nimage = '') { if ($nimage) { $this->setImage = $nimage; } } public function setImage($nimage) { if ($nimage) { $this->nimage = $nimage; } return $this; } public function callback() { return $this->nimage; } public function crop($x = 10, $y = 100, $width = 400, $height = 400) { $temp = imagecreate($width, $height); imagecopy($temp, $this->nimage, 0, 0, $x, $y, $width, $height); $this->nimage = $temp; return $this; } public function border($px = 5, $colour = array('255', '255', '255')) { $img_width = $this->getImageWidth() + (2 * $px); $img_height = $this->getImageHeight() + (2 * $px); $temp = imagecreate($img_width, $img_height); $border = imagecolorallocate($temp, $colour[0], $colour[1], $colour[2]); if (!is_array($colour)) { $border = imagecolorallocatealpha($temp, 0, 0, 0, 127); } else { $border = imagecolorallocate($temp, ($colour[0]) ? $colour[0] : 0, ($colour[1]) ? $colour[1] : 0, ($colour[2]) ? $colour[2] : 0); } imagefilledrectangle($temp, 0, 0, $img_width, $img_height, $border); imagecopy($temp, $this->nimage, $px, $px, 0, 0, $this->getImageWidth(), $this->getImageHeight()); $this->nimage = $temp; return $this; } public function rotate($angle = 90, $bg_colour = 0) { $this->nimage = imagerotate($this->image, $angle, $bg_colour, 0); return $this; } public function quick() { header('Content-type: image/png'); imagepng($this->nimage); } private function getImageWidth() { return (int)imagesx($this->nimage); } private function getImageHeight() { return (int)imagesy($this->nimage); } } function wait($time) { /* I like the name wait() */ return sleep($time); } /** Example usage: $screen = new screenshot(true, 720, 500); $screen->set_visible(true); $screen->navigate('http://google.com'); $screen->title('You can set custom titles too (and custom body if you want)'); $screen->position(0, 0); $screen->capture(); $screen->save('image.png'); $screen->manipulate(); $screen->manipulate->setImage($screen->getimage()); $screen->manipulate->crop(10, 100, 685, 390); $screen->manipulate_end($screen->manipulate->callback()); $screen->output(); $screen->quit(); */ ?> PHP:
I know there's been a few places posted in here, but I found one called MPZImg a few days ago that seems a bit cheaper than most and has some decent PHP examples on there. Might have a look at that MS solution tho, is it free?
Ok, let's go pro for a bit (assuming you are going to use a dedicated server or a VPS): http://code.google.com/p/wkhtmltopdf/ Left menu bar, download the wkhtml2img, install it in your server and bind it via php. Then you create your API and sell access to others
You can try https://browshot.com/ (100 free screenshots a month): PHP library at https://github.com/juliensobrier/browshot-php examples using PHP at https://browshot.com/api/libraries/php Full API description at https://browshot.com/api/documentation
imagescreengrab - Captures the whole screen - a PHP-script that scrapes 500 different sites and stores the results as thumbnails. Refer this link, you can get some idea from that. http://stackoverflow.com/questions/757675/website-screenshots-using-php
The easiest way to create screenshots using a PHP script is to use a third party service like GrabzIt's PHP API: http://grabz.it/api/php/
Even if you be able to get/make script for screenshoting, it's heavy server resource task, and most important, all libraries you need won't be available on shared hosting....been there already There are few sites giving you API where you can fetch screenshots from them, cost is usually $5 per month...do research