It is obviously possible to construct a poor-man version in standalone vbs for checking image size according to Shaddow's line. Here is a possible throw-away realization.
'---------
'Fix your absolute path & image name---it is necessary
Const strWrkDir="C:\winnt\system32\"
Const strImgName = "snapin.gif"
Const strTmpFileName = "tmp.htm"
intBuild=0
BuildHTML strWrkDir&strImgName,strWrkDir&strTmpFileName,intBuild
Select Case intBuild
Case 0 WScript.Echo "Unidentified failure. Operation aborted."
Case 1 WScript.Echo "Image file cannot be found."
Case 2 WScript.Echo "Check disk space & file system. Operation aborted."
End Select
If intBuild <3 Then
WScript.Quit
End If
Set oIE=WScript.CreateObject("InternetExplorer.Application","IE_"
oIE.Visible=false
'oIE.Visible=true 'An acceptable alternative
oIE.navigate strWrkDir&strTmpFileName
Do while oIE.busy
WScript.Sleep 500
Loop
ToDeleteFile strWrkDir&strTmpFileName
If oIE.visible Then
WScript.Sleep 5000 '5 sec visual inspection
End If
oIE.Quit
WScript.Quit
Sub IE_onQuit
'WScript.Echo "User manually quitted the program."
Set oIE=Nothing
WScript.Quit
End Sub
Sub BuildHTML(ImgFile, HTMLFile, intReturn)
On Error Resume Next
intReturn=0
Set fso=WScript.CreateObject("Scripting.FileSystemObject"
If Not fso.FileExists(ImgFile) Then
Set fso=Nothing
Exit Sub
End If
intReturn=1
strTag="<image name="""&ImgFile&""" src=""" & ImgFile & """" & _
" onLoad=""alert(this.name+"&chr(39)&":"&chr(39)&"+ this.width+"& _
chr(39)&"x"&chr(39)&"+this.height)"">"
Set oHTML=fso.CreateTextFile(HTMLFile,True)
oHTML.WriteLine("<HTML><HEAD></HEAD><BODY>"
oHTML.WriteLine(strTag)
oHTML.WriteLine("</BODY></HTML>"
oHTML.close
If err.number<>0 Then
intReturn=2 'Failed to create HTMLFile
err.clear
Else
intReturn=3 'completely successful
End If
On Error GoTo 0
Set oHTML=Nothing
Set fso=Nothing
End Sub
Sub ToDeleteFile (strFileName)
On Error Resume Next
Set fso=WScript.CreateObject("Scripting.FileSystemObject"
'wscript.echo strFileName
If fso.FileExists(strFileName) Then
Do
err.clear
fso.DeleteFile(strFileName)
Loop While err.number<>0
End If
On Error GoTo 0
Set fso=Nothing
End Sub
'---------
A few notes for improving:
[1] I use instead onLoad to avoid to many interactives. But, then if the system is excessively slow, it might pop up a wrong 0x0 pixcel size.
[2] From this sketch, you can develop a drag-&-drop to input the specific image file to use.
[3] The tmp.html file can be created in the system specific tmp folder if it looks better.
[4] The output is visual & need a click. It is inconvenient and can obviously be improved.
[5] Input in batch.
I had not used Option Explicit, I like to and should have. But I was being lazy as I wrote those lines on the fly. I have tested it though.
This is just an exercise for my own pleasure. If you find it useful in one or two tricks used, that is an anonymous bonus to me.
[1] A reason for me coming back is to point out some pretty obvious careless mistakes in my throw-away script related to the intReturn.
Sub BuildHTML(ImgFile, HTMLFile, intReturn)
On Error Resume Next
intReturn=0
Set fso=WScript.CreateObject("Scripting.FileSystemObject"
If err.number<>0 Then
Set fso=Nothing
Exit Sub
End If
intReturn=1
If Not fso.FileExists(ImgFile) Then
Set fso=Nothing
Exit Sub
End If
intReturn=2
...etc
End Sub
[2] Then in the main, Select Case is corrected accordingly,
...etc
Select Case intBuild
Case 0 WScript.Echo "Runtime Scripting failure. Operation aborted."
Case 1 WScript.Echo "Image file cannot be found."
Case 2 WScript.Echo "Check disk space & file system. Operation aborted."
End Select
...etc
[3] Here, the main reason of my coming back is to resolve the time problem of using onLoad event. Below is the minimal way to implement a check of image.complete test in an HTML page I would use:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function letLoad() {
if (!document.images[0].complete) {
setTimeout("letLoad()",5);
} else {
alert(document.images[0].complete+" "+document.images[0].name+':'+document.images[0].width+'x'+document.images[0].height);
}
}
</SCRIPT>
</HEAD>
<BODY>
<img name="Shed in Field.jpg" src="Shed in Field.jpg" onLoad="letLoad()">
</BODY>
</HTML>
with Shed in Field.jpg is the image file.
So, the obvious thing is to implement this in the strTag. This is obvious, I won't elaborate.
[3] I want just repeat that complete loading does pose a problem for a standalone script. People may not observe that without revision I made. But, I have a slow system to work with which show acutely the problem running the script.
[4] Drag-and-drop or reading a list of file remain a good exercise to extend the script.
[5] I must say I seem unnecessary insistent not because I think the script is of any value, but, because I just want to at least make it deliver a use.
[6] strongm, yours is a good piece of info. Not familiar with the use of it. But loadpicture does have a place in the vbscript documentation. I have learned something, as usual, thanks.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.