GetImageDimensionProperty(ImgPath, Byref width, Byref height, PropertyName="dimensions")
Retrieves width and height of a specified image file.Code:
GetImageDimensionProperty(ImgPath, Byref width, Byref height, PropertyName="dimensions") {
Static DimensionIndex
SplitPath, ImgPath , FileName, DirPath,
objShell := ComObjCreate("Shell.Application")
objFolder := objShell.NameSpace(DirPath)
objFolderItem := objFolder.ParseName(FileName)
if !DimensionIndex {
Loop
DimensionIndex := A_Index
Until (objFolder.GetDetailsOf(objFolder.Items, A_Index) = PropertyName) || (A_Index > 300)
}
if (DimensionIndex = 301)
Return
dimensions := objFolder.GetDetailsOf(objFolderItem, DimensionIndex)
width := height := ""
pos := len := 0
loop 2
{
pos := RegExMatch(dimensions, "O)\d+", oM, pos+len+1)
if (A_Index = 1)
width := oM.Value(0), len := oM.len(0)
else
height := oM.Value(0)
}
}
GetImageDimensions(ImgPath, Byref width, Byref height)Code:
GetImageDimensions(ImgPath, Byref width, Byref height) {
DHW := A_DetectHiddenWIndows
DetectHiddenWindows, ON
Gui, AnimatedGifControl_GetImageDimensions: Add, Picture, hwndhWndImage, % ImgPath
GuiControlGet, Image, AnimatedGifControl_GetImageDimensions:Pos, % hWndImage
Gui, AnimatedGifControl_GetImageDimensions: Destroy
DetectHiddenWindows, % DHW
width := ImageW, height := ImageH
}
Example:Code:
ImageFile := A_ScriptDir "\logo.gif"
if !FileExist(ImageFile)
UrlDownloadToFile, http://www.autohotkey.com/docs/images/AutoHotkey_logo.gif, % ImageFile
GetImageDimensions(ImageFile, w, h)
msgbox % "Width:`t" w "`nHeight:`t" h
Ruirements: AutoHotkey 1.1.05 or later. The details are found in the link.