Monthly Archives: August 2006

Save html to gif

Htmlsnapshot supports converting html to gif. And it supports creating transparent GIF as well.

The SetGIFOption can be used to enable or disable transparent Gif

Dim snap
Set snap = CreateObject(“HTMLSNAP2.HtmlSnap.1″)
snap.SetTimeOut CLng(200000)

‘disable transparency gif
snap.SetGIFOption FALSE, &HFFFFFFFF
snap.SnapUrl “http://www.google.com/“, “0.gif”

‘enable transparency gif
snap.SetGIFOption TRUE, &HFFFFFFFF
snap.SnapUrl “http://www.google.com/“, “1.gif”

 

 

Create high quality image from html

htmlsnapshot generates the image at the screen DPI by default. To get a higher resolution image, there are two methods.

1. Use setzoom and setDPI method.  The following code zooms the image 3 times and set DPI as 300, 300

  Dim snap
Set snap = CreateObject(“HTMLSNAP2.HtmlSnap.1″)
snap.SetTimeOut CLng(200000)

snap.SetDPI 300, 300
snap.SetZoom 3.0
snap.SnapUrl “d:temprptfile_200608140039.html”, “zoom.tif”

Set snap = Nothing

2.  generate a metafile first and convert it into raster image

 ’Declare object
Dim snap
Set snap = CreateObject(“HTMLSNAP2.HtmlSnap.1″)
snap.SetTimeOut CLng(200000)

snap.SnapUrl “file://d:temprptfile_200608140039.html“, “2.emf”

snap.SetDPI 300, 300

‘convert emf to tif, keep aspect ratio
snap.ConvertEMFToImage “2.emf”, “1.tif”, 6000, 6000, 1

Set snap = Nothing

 

Convert VML To image

VML is a kind of vector based graphic format.

html snapshot can convert VML to image like jpg, tiff etc. 

In Win2003, there is an “IE enhanced security” component which may restrict some behaviour of rending vml to image.  

So to make  vml to image work correctly, it is safer to remove the security component from Windows.  You can do this from the “Add/Remove software” control panel.

 

 

Write image back to browser

Want to send an image from php to browser?  You can use code like this

< ?php
header('Content-type: image/jpg');
readfile('your.jpg');
?>

 

For using with htmlsnapshot, the code is like this

 < ?php

$snap = new COM("HTMLSNAP2.HtmlSnap.1");
header('Content-type: image/jpg');

$snap->SnapUrl(www.google.com, “*”)
print $snap->GetImageBytes(“*.jpg”)
?>