Tutorial: Install php and run html snapshot with IIS

So you are a PHP fan that wants to convert html to image? You can do it with html snapshot with php on windows server. This tutorial shows how to do this with php and IIS. ( Apache for windows can also be used as well.)

My steps (based on Win2003)
1. Download php for win32 from php.net
http://www.php.net/downloads.php

Using PHP 5.1.4 zip as example,
extract the files to c:php

Following the instruction here to enable php in IIS
http://www.simongibson.com/intranet/php2003/
2. Write a small php with the expression and put it to c:inetpubwwwroot to test if php works
. Make sure it is ok

3. Download html snapshot free trial. Install it on the server. Get the php demo and put it in wwwroot. Make sure your IIS account (IUSR_MachineName) can write to the folder that will save the image file.  Alternatively, you can also call SetLogOnUser before calling SnapUrl.

 The example code I used is here:

< ?php

$url = “http://www.google.com/“;
$path = getcwd().”\”;
$img = “1.jpg”;
$timg = “1s.jpg”;

$com = new COM(“HTMLSNAP2.HtmlSnap.1″);

$com->SetLogOnUser(“user”, “.”, “user”);

$com->SnapUrl($url, $path.$img );

$com->GetThumbnailImage($path.$img, $path.$timg, 100, 100, 1);

print “Snapshot of “.$url.”. Click to enlarge
“;
 
?>

Load the php page in IE, you will find the image converted from html in your wwwroot folder.  

Note that I call SetLogOnUser method with an account named “user”. This could be an account that is created specially for converting html to image. You can give him enough privilege to write files or loading ActiveX like flash movie. It can be an Administrator account (needed for capturing flash). Security concern? It is no problem since Html snapshot will only impersonate that user when doing html to image. It will revert to normal web user after SnapUrl call. So it is secure. :)