The following code extracts an image from html,
Function getphoto (strHTML)
Dim objRegExp, Match, Matches
Set objRegExp = New Regexp
ObjRegExp. IgnoreCase = True
ObjRegExp. Global = True
ObjRegExp. Pattern = " "
Tp = ""
Set Matches = objRegExp. Execute (strHTML)
For Each Match in Matches
Tp = tp & Match. value
Exit
Next
Getphoto = tp
Set objRegExp = Nothing
End Function
The following code scales the image proportionally.
Function ResizeImage (imageid, limitWidth, limitHeight)
{
Var image = new Image ();
Image. src = imageid. src;
If (image. width <= 0 & image. height <= 0) return;
If (image. width/image. height> = limitWidth/limitHeight)
{
If (image. width> limitWidth)
{
Imageid. width = limitWidth;
Imageid. height = (image. height * limitWidth)/image. width;
}
}
Else if (image. height> limitHeight)
{
Imageid. height = limitHeight;
Imageid. width = (image. width * limitHeight)/image. height;
}
If (imageid. parentElement. tagName! = "")
{
Imageid. onclick = function () {window. open (this. src );}
Imageid. style. cursor = "hand ";
}
}
Window. onload = InitImages;
Function InitImages ()
{
// Constrain width and height of the image
Var maxWidth = 100;
Var maxHeight = 100;
Var imgs = document. getElementsByTagName ("img ");
For (var I = 0; I {
Var img = imgs;
If (img. width> maxWidth | img. height> maxHeight)
ResizeImage (img, maxWidth, maxHeight );
}
}