Home > PHP > HTML Webpage to Image On Windows – OS Dependent

HTML Webpage to Image On Windows – OS Dependent

Note:

  • It works only with Windows OS –  OS Dependent

Steps:

  1. Download and install webthumb-activex-setup.exe from http://www.acasystems.com/en/web-thumb-activex/download.htm
  2. Then paste the below code and save as imageGrap.php

<?php

// Set the save folder

  // [IMPORTANT NOTE]:

  // This sample saves the snapshot to the folder on the work dir of this script.

  // Please make sure the script has the WRITE permission in this folder.

  // You can also set the value to other folder, for example:

  //   $t_strSaveFolder = “c:/temp”;

  $t_strSaveFolder = dirname(__FILE__);

  // Set the image filename

  $t_strLargeImage = $t_strSaveFolder.”/main-thumb.large.png”;

  $t_strSmallImage = $t_strSaveFolder.”/main-thumb.small.png”;

  // Create instance ACAWebThumb.ThumbMaker.

  $t_xMaker = new COM(“ACAWebThumb.ThumbMaker”)

    or die(“Start ACAWebThumb.Maker failed”);

  // Set the URL and start snap

  $t_strURL = ‘http://www.sitename-xxxxx.com/&#8217;; // Site URL

  $t_xMaker->SetURL($t_strURL);

  $t_iRet = $t_xMaker->StartSnap();

  if ( 0 == $t_iRet )

  {

    // snap successful, save webpage to image with full size.

    $t_bRet1 = $t_xMaker->SaveImage($t_strLargeImage);

    // save webpage to thumbnail with 320×240 size

    $t_xMaker->SetThumbSize (320, 240, 0);

    $t_bRet2 = $t_xMaker->SaveImage($t_strSmallImage);

    // show the image online.

    if ( $t_bRet1 && $t_bRet2)

    {

      echo “The snapshot from <a href='”.$t_strURL.”‘ target=_blank>”.$t_strURL.”</a>:”;

      echo “<a href=’main-thumb.large.png’>img src=’main-thumb.small.png’ border=1></a>”;

    }

    else

    {

      echo “ERROR: Can’t save the snapshot to folder “.dirname(__FILE__).”. “;

      echo “Please make sure the script has the WRITE PERMISSION in this folder.”;

    }

  }

  else

    echo “ERROR: Snap from “.$t_strURL.” failed. “;

?>

3. Run the file, we will get the Webpage as image on the same folder.

Advertisements
Categories: PHP
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: