HtmlString includes a web page, and soon it is converted to Html file.
In the web page, they are images, and some of them are large. They are so large, in fact they are going to destroy my Tables, so I need to resize these images.
I write a Function to do this job.
[COLOR=DarkOrange]Resizeimage(HtmlString)[/COLOR]
[COLOR=SeaGreen]Function Resizeimage(ConStr)
Dim TempStr,Re,Matches,Match,Tempi,TempArray
Set Re = New Regexp
Re.IgnoreCase = True
Re.Global = True
Re.Pattern ="<img.+?[^\>]>"
Set Matches =Re.Execute(ConStr)
For Each Match in Matches
If TempStr<>"" then
TempStr=TempStr & "$Array$" & Match.Value
Else
TempStr=Match.Value
End if
Next
If TempStr<>"" Then
TempArray=Split(TempStr,"$Array$")
TempStr=""
For Tempi=0 To Ubound(TempArray)
Re.Pattern ="src\s*=\s*.+?\.(gif|jpg|bmp|jpeg|psd|png|svg|dxf |wmf|tiff)"
Set Matches =Re.Execute(TempArray(Tempi))
For Each Match in Matches
If TempStr<>"" then
TempStr=TempStr & "$Array$" & Match.Value
Else
TempStr=Match.Value
End if
Next
Next
End if
If TempStr<>"" Then
Re.Pattern ="src\s*=\s*"
TempStr=Re.Replace(TempStr,"")
End If
Set Matches=nothing
Set Re=nothing
If TempStr="" or IsNull(TempStr)=True Then
ReplaceSaveRemoteFile=ConStr
Exit function
End if
TempStr=Replace(TempStr,"""","")
TempStr=Replace(TempStr,"'","")
TempStr=Replace(TempStr," ","")
Dim PathTemp
TempArray=Split(TempStr,"$Array$")
TempStr=""
For Tempi=0 To Ubound(TempArray)
If Instr(Lcase(TempStr),Lcase(TempArray(Tempi)))<1 Then
TempStr=TempStr & "$Array$" & TempArray(Tempi)
End If
Next
TempStr=Right(TempStr,Len(TempStr)-7)
TempArray=Split(TempStr,"$Array$")
Set Re = New Regexp
Re.IgnoreCase = True
Re.Global = True
For Tempi=0 To Ubound(TempArray)
Re.Pattern =TempArray(Tempi)
PathTemp=TempArray(Tempi)
PathTemp=PathTemp&"' onclick='javascript:window.open(this.src);' onload='javascript:if(this.width>screen.width-300)this.style.width=screen.width-300;"
ConStr=Re.Replace(ConStr,PathTemp)
Next
Set Re=nothing
Resizeimage=ConStr
End function[/COLOR]
this founction works well with the first few files,but I met problem soon.