Provide state-of-the-art image capture, screen capture, video capture and audio capture software
Home     Download     Purchase     Support     Contact     View my shopping cart
You are here: ACASystems » ACA WebThumb ActiveX Control » FAQ » Convert webpage to image with PHP

How to convert webpage to image using PHP? - PHP Sample Code(2)

This article shows a solution for converting webpage to image with PHP. If you are a webmaster or web developer, you may want to show the webpage thumbnail image in your website. ACA WebThumb ActiveX can help you to implement converting webpage to image with a few funcion call in PHP, it helps you convert html page from any URL to image or thumbnails easily and quickly, takes the snapshots of given URLs as JPG, GIF, PNG, BMP, TIFF, WMF and EMF image.

Guidelines: Convert webpage to image with PHP

  1. Free download ACA WebThumb ActiveX, and then install it.
  2. You will find rich php sample scripts in the folder {install-folder}\sample\php.
  3. You can copy these sample scripts to your local WWW folder and then open it.

Free Trial ACA WebThumb ActiveX Now

Example code: Convert webpage to webpage with PHP

PHP script code for converting webpage to image:

<?
  // 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.acasystems.com';
  $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 320x240 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. ";
?>

Free Trial ACA WebThumb ActiveX Now

Other resource about Converting webpage to image with PHP:

Other Resources for Webmasters


Get discount alerts, new product information and technical articles:
Name:
Email:
* Get 10% off your first order by joining our mailing list!
* You may safely unsubscribe at any time!