Post by jeeswg » 04 Sep 2019, 19:39
I wrote some code to test the IMG_GetImageSize function.
Note: I had to determine which extensions to check. Do suggest any extensions that I missed.
Code: Select all
;[IMG_GetImageSize function]
;Expert Challenge: Get width and height from an image file reading as few bytes as possible. - Page 2 - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=17&t=66880
;get image dimensions via GetDetailsOf and via IMG_GetImageSize
#NoEnv
SetBatchLines, -1
ListLines, Off
;vDir1 := "C:\Users\" A_UserName "\Pictures"
vDir1 := "C:"
vOutput := ""
VarSetCapacity(vOutput, 1000000*2)
;note: tabbed: extensions I see in image search results
vListExt := " ;continuation section
(
ani
bmp
cur
emf
gif
ico
jpg (jpeg, jpe, jif, jfif, jfi)
pcx
png
svg
tif
wdp (hdp, jxr)
webp
wmf
)"
vListExt := RegExReplace(vListExt, "\W+", ",")
MsgBox, % vListExt
vCount := 0
Loop Files, % vDir1 "\*", % "FR"
{
vPath := A_LoopFileFullPath
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
if vExt not in % vListExt
continue
IMG_GetImageSize(vPath, vImgW1, vImgH1)
vImgW2 := RegExReplace(JEE_FileGetDetail(vPath, "Width"), "\D")
vImgH2 := RegExReplace(JEE_FileGetDetail(vPath, "Height"), "\D")
;if !(vImgW1 " " vImgH1 = vImgW2 " " vImgH2)
; MsgBox, % vPath "`r`n" vImgW1 " " vImgH1 "`r`n" vImgW2 " " vImgH2
if !(vImgW1 " " vImgH1 = vImgW2 " " vImgH2)
vOutput .= vPath "`t" vImgW1 " " vImgH1 "`t" vImgW2 " " vImgH2 "`r`n"
, vCount++
}
vPath := A_Desktop "\z img sizes " A_Now ".txt"
FileAppend, % vOutput, % "*" vPath, UTF-8
MsgBox, % "done"
return
;==================================================
;JEE_FileGetProperty
;JEE_FileGetProperties
;this term (e.g. 'Length') may vary depending on the locale
JEE_FileGetDetail(vPath, vDetail)
{
local
static oMap := IsFunc("Map") ? Func("Map").Call() : {}
if !FileExist(vPath)
return
SplitPath, vPath, vName, vDir
oShell := ComObjCreate("Shell.Application")
oFolder := oShell.NameSpace(vDir "\")
oFilename := oFolder.Parsename(vName)
if oMap.HasKey("z" vDetail)
{
vValue := oFolder.GetDetailsOf(oFilename, oMap["z" vDetail])
oShell := oFolder := oFilename := ""
return vValue
}
Loop
{
vDetail2 := oFolder.GetDetailsOf(oFolder.Items, A_Index-1)
if (vDetail2 = "")
break
if (vDetail = vDetail2)
{
vValue := oFolder.GetDetailsOf(oFilename, A_Index-1)
oMap["z" vDetail] := A_Index-1
break
}
}
oShell := oFolder := oFilename := ""
return vValue
}
;==================================================
I wrote some code to test the IMG_GetImageSize function.
Note: I had to determine which extensions to check. Do suggest any extensions that I missed.
[code]
;[IMG_GetImageSize function]
;Expert Challenge: Get width and height from an image file reading as few bytes as possible. - Page 2 - AutoHotkey Community
;https://autohotkey.com/boards/viewtopic.php?f=17&t=66880
;get image dimensions via GetDetailsOf and via IMG_GetImageSize
#NoEnv
SetBatchLines, -1
ListLines, Off
;vDir1 := "C:\Users\" A_UserName "\Pictures"
vDir1 := "C:"
vOutput := ""
VarSetCapacity(vOutput, 1000000*2)
;note: tabbed: extensions I see in image search results
vListExt := " ;continuation section
(
ani
bmp
cur
emf
gif
ico
jpg (jpeg, jpe, jif, jfif, jfi)
pcx
png
svg
tif
wdp (hdp, jxr)
webp
wmf
)"
vListExt := RegExReplace(vListExt, "\W+", ",")
MsgBox, % vListExt
vCount := 0
Loop Files, % vDir1 "\*", % "FR"
{
vPath := A_LoopFileFullPath
SplitPath, vPath, vName, vDir, vExt, vNameNoExt, vDrive
if vExt not in % vListExt
continue
IMG_GetImageSize(vPath, vImgW1, vImgH1)
vImgW2 := RegExReplace(JEE_FileGetDetail(vPath, "Width"), "\D")
vImgH2 := RegExReplace(JEE_FileGetDetail(vPath, "Height"), "\D")
;if !(vImgW1 " " vImgH1 = vImgW2 " " vImgH2)
; MsgBox, % vPath "`r`n" vImgW1 " " vImgH1 "`r`n" vImgW2 " " vImgH2
if !(vImgW1 " " vImgH1 = vImgW2 " " vImgH2)
vOutput .= vPath "`t" vImgW1 " " vImgH1 "`t" vImgW2 " " vImgH2 "`r`n"
, vCount++
}
vPath := A_Desktop "\z img sizes " A_Now ".txt"
FileAppend, % vOutput, % "*" vPath, UTF-8
MsgBox, % "done"
return
;==================================================
;JEE_FileGetProperty
;JEE_FileGetProperties
;this term (e.g. 'Length') may vary depending on the locale
JEE_FileGetDetail(vPath, vDetail)
{
local
static oMap := IsFunc("Map") ? Func("Map").Call() : {}
if !FileExist(vPath)
return
SplitPath, vPath, vName, vDir
oShell := ComObjCreate("Shell.Application")
oFolder := oShell.NameSpace(vDir "\")
oFilename := oFolder.Parsename(vName)
if oMap.HasKey("z" vDetail)
{
vValue := oFolder.GetDetailsOf(oFilename, oMap["z" vDetail])
oShell := oFolder := oFilename := ""
return vValue
}
Loop
{
vDetail2 := oFolder.GetDetailsOf(oFolder.Items, A_Index-1)
if (vDetail2 = "")
break
if (vDetail = vDetail2)
{
vValue := oFolder.GetDetailsOf(oFilename, A_Index-1)
oMap["z" vDetail] := A_Index-1
break
}
}
oShell := oFolder := oFilename := ""
return vValue
}
;==================================================
[/code]