We just released a new version of html to image. A coupe of issues are fixed.
Please welcome download and try freely!
We just released a new version of html to image. A coupe of issues are fixed.
Please welcome download and try freely!
Sometimes you may want to use html2image in an enviroment that needs to set proxy.
One of our customers shares his tip on this problem. here it is:
./html2image/greprefs/all.js
.Example below, this is the standard firefox proxy setting
pref(“network.proxy.autoconfig_url”, “http://myProxy/myScript”);
pref(“network.proxy.type”, 2);
If you have any comments on this solution, let us know!
X64 windows is becoming more and more polular platform. Htmlsnapshot component has supported html to image on windows x64 platform along with the industry trend.
There are mainly four x64 windows: XP x64, Vista X64, Windows 2003 x64, Windows 2008 X64. The first two are client platform while the last two are server version.
To convert html to image on windows x64 platform, there are two ways:
1. Convert html to image with the 32 bit component. To do this, html to image function must run under a 32 bit process. By default, htmlsnapshot will register itself as 32 bit component on Windows X64/
For example, you can run the simple vbscript demo with 32 bit mode like this:
c:WindowsSysWOW64cscript.exe DemoVBScriptsimple.vbs
2. Convert html to image with native 64bit mode. Since IE has been ported to x64, so htmlsnapshot can capture html to image with 64 bit IE. To do this, first you need to manual register the 64 bit htmlsnapshot. In the installation folder, run below command:
regsvr32 x64htmlsnap2.dll
Now, you can run the simple vbscript demo with 64bit mode like this:
c:Windowssystem32cscript.exe DemoVBScriptsimple.vbs
Another thing to notice is that in order to capture html page with flash to image, you has to use the 32 bit mode. The reason is that the flash player doesn’t have 64 bit version yet. Adobe is still working on this. Please read:
http://kb.adobe.com/selfservice/viewContent.do?externalId=6b3af6c9&sliceId=2
Here is detailed example on how to use html2image linux on Ubuntu 64 bit (Ubuntu 7.10 – the Gutsy Gibbon)
This serves as a good example on how to use html2image. Other 64 bit Linux distribution can be done similarly.
1. Install Ubuntu 64
2. Login into the server (you can use the text mode login here. This is suitable for headless server as well)
If you are in GUI mode, Ctrl+Alt+F2 will switch you to text mode.
3. Enter a folder, download html2image
wget http://www.guangmingsoft.net/htmlsnapshot/html2image.i386.tar.gz
4. Extract html2image
tar xvzf html2image.i386.tar.gz
cd html2image
export LD_LIBRARY_PATH=./
4. Install 32bit application support libraries.
sudo apt-get install ia32-libs
5. Install Xvfb coming with the Ubuntu
sudo apt-get install xvfb
6. Run Xvfb
Xvfb :1 -screen 0 640x480x24 -nolisten tcp -audit 4 -auth X1.cfg & export DISPLAY=:1
Of course, you could try high resolution like 1024x768x24
7. Now you can run html2image, it should work
./html2image www.google.com a.jpg
Check if the a.jpg is created successfully.
Here are a more complete examples of using htmlsnapshot to convert html to image with php on Windows.
Note the following things:
1. You copy/paste the below code into test.php and run on command line
php.exe test.php
2. Yon can see it uses GetErrorCode to handle errors to make your code more robust.
<?php
$url = “http://google.com/“;
$path = “.\”;
$img = “1.jpg”;
$timg = “1s.jpg”;
$limg = “1b.jpg”;
$iimg = “1i.jpg”;$com = new COM(“HTMLSNAP2.HtmlSnap.1″);
$com->SetTimeout(150000);
$com->SetDelayTime(5000);
$com->EnableActiveX(true);
$com->EnableJava(true);
$com->EnableScript(true);
$com->EnableActiveX(true);
$com->SetJPEGQuality(100);
$com->SetSmoothingMode(2);
$com->SetInterpolationMode(6);
$com->SnapUrl($url, $path.$img );$err = $com->GetErrorCode();
if ($err == 1)
{$com->SetClipRect(0, 0, 1024, 768);
$com->SaveImage($path.$iimg);$com->GetThumbnailImage($path.$img, $path.$timg, 160, 120, 0);
$com->GetThumbnailImage($path.$img, $path.$limg, 320, 240, 0);
$com->Clear();print “Snapshot of “.$url.”. Click to enlarge<br>”;
print “<a href=”.$iimg.” mce_href=”.$iimg.”><img src=”.$timg.” mce_src=”.$timg.”><img src=”.$limg.” mce_src=”.$limg.”></a><br/>”;
}
else
{
print “error happens”;
}
?>
You may need to run a command line utility to convert html or url to image. Here is a handy script that converts url/html to image with our award winning htmlsnapshot product.
Save the below code into a script snapurl.vbs (Or you can find this script in htmlsnapshotdemovbscript)
set args = WScript.Arguments
num = args.Countif num <> 2 then
WScript.Echo “Usage: [CScript | WScript] snapurl.Vbs Url ImageFile”
WScript.Quit 1
end if‘demo how to convert html to image
Dim snap‘Create the Html Snapshot Object
Set snap = CreateObject(“HTMLSNAP2.HtmlSnap.1″)
snap.SetCode “Input your license code here to remove watermark”
snap.SnapUrl args.Item(0), args.Item(1)
WScript.echo “Snap return:” & CStr(snap.GetErrorCode)‘Free object
Set snap = Nothing
After that, you can run on command line like below:
cscript.exe snapUrl.vbs www.google.com g.jpg
cscript.exe snapUrl.vbs file://c:1.html g.jpg
Silverlight is the new web authoring technology proposed by Microsoft. It is implemented as an ActiveX like the Flash.
It can be used to build interactive, vector based web pages.
To convert such web page into image, you can do it with our award winning htmlsnapshot product.
Htmlsnapshot now supports converting html into multiple page tiff files. here is the sample code. You just need to specify the page width in pixel. The component will save the image into a multipage tif.
‘demo html to multipage tiff generation function
Set WshShell = WScript.CreateObject(“WScript.Shell”)
‘Declare object
Dim snap
Set snap = CreateObject(“HTMLSNAP2.HtmlSnap.1″)
snap.SetTimeOut CLng(200000)
snap.SnapUrl “http://www.google.com/“, “google.tiff”‘Set CCITT3 encoding for TIFF
snap.SetTIFFEncoder 1
snap.SaveMultipageTiff “m-google-ccitt-3.tiff”, 200‘Set CCITT4 encoding for TIFF
snap.SetTIFFEncoder 2
snap.SaveMultipageTiff “m-google-ccitt-4.tiff”, 200‘Set RLE encoding for TIFF
snap.SetTIFFEncoder 3
snap.SaveMultipageTiff “m-google-rle.tiff”, 200‘Set none encoding for TIFF
snap.SetTIFFEncoder 4
snap.SaveMultipageTiff “m-google-none.tiff”, 200snap.SetTIFFEncoder 1
‘Change thresholding when converting to monochrome
snap.SetThreshold 200
snap.SaveMultipageTiff “m-google-ccitt-4-1.tiff”, 200Set snap = Nothing
It is possibe to use html CSS sheet with SnapHtmlString when converting a html string to image. The trick is to store the css in a local file and refer to it in the html string like below:
<link href=”file://c:/Styles.css” rel=”stylesheet” type=”text/css” />
Then you can use htmlsnapshot to capture the html string into image with the CSS specified.