Generating Website Thumbnails in PHP

By | October 5, 2012

In recent web browser development  one of the new features is the generation of site thumbnail images displayed in a gallery. In Opera, it has a feature called Speed Dial Thumbnail, in Google Chrome, it has a page that displays thumbnail for Most Visited, Recent Bookmarks and Recently closed tabs, while in Internet Explorer 7, they call this feature as Quick Tabs. This promotes easier recall for users rather than remembering the exact URL address.

The following codes below can replicate the same thumbnail generation feature in PHP using only Internet Explorer browser. This is helpful if you wish to advertise your sponsors’ sites or display other webpages that you want to recommend.

//*** PHP 5 with GD is required for this to work and IE client browser

function thumb_image($img_file,$url)
//** initiate a browser session for screen capture
$browser = new COM(“InternetExplorer.Application”);
$handle = $browser->HWND;
$browser->Visible = true;
$browser->Fullscreen = true;

while ($browser->Busy) {

$im = imagegrabscreen(); //** works only with IE, captures the whole screen
imagepng($im, “tmp_”.$img_file); //** store workfile

$percent = 0.20;   //** factor of thumbnail reduction = 20%
list($width, $height) = getimagesize(“tmp_”.$img_file);
$new_width = floor($width * $percent);
$new_height = floor($height * $percent);

//// Resample
$im2 = imagecreatetruecolor($new_width, $new_height);
imagecopyresampled($im2, $im, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

imagepng($im2, $img_file); //** save url image into specified file_name
imagedestroy($im); imagedestroy($im2);


thumb_image(“facebook.png”,”“); /
/** call the function
print “<img src=facebook.png>”; echo “<br><br>”;
//** use captured image like any regular picture


Courses you may be interested in:


Leave a Reply

Your email address will not be published. Required fields are marked *