Jump to content

any way to get an image's dimensions (pixels in X & Y direction) ?


Go to solution Solved by ioa747,

Recommended Posts

Is there any way to get an image's dimensions (pixels in X & Y direction) ?
I can see the dimensions using one of the Windows File Explorer, details view, extra columns.

My images are pretty much all the same size for a 'session', so this isn't too important.
I can always 'hard code' this into each instance of my script and just put the dimensions in the filename.

 

Link to comment
Share on other sites

Link to comment
Share on other sites

On 7/20/2024 at 12:19 AM, Nine said:

Alternatively, you can use _WinAPI_GetBitmapDimension (see help file).  But _WinAPI_LoadImage is much more restrictive in terms of file types you can read.

Tried but output dimensions using the example image showed as 0,0 instead of 400,400. 

Link to comment
Share on other sites

  • Solution
Posted (edited)

 

Local $aDim =  _GetImageDimensions("C:\Program Files (x86)\AutoIt3\Examples\GUI\logo_autoit_210x72.gif")
ConsoleWrite($aDim[0] & "x" & $aDim[1] & @CRLF)

Func _GetImageDimensions($sPath)
    Local $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
    Local $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))
    Local $oShellApp = ObjCreate("shell.application")
    Local $oDir = $oShellApp.NameSpace ($sDir)
    Local $oFile = $oDir.Parsename ($sFile)
    Local $aDimension[2]
    $aDimension[0] = $oFile.ExtendedProperty("System.Image.HorizontalSize")
    $aDimension[1] = $oFile.ExtendedProperty("System.Image.VerticalSize")
    Return $aDimension
EndFunc   ;==>_GetProperty


More:

Edited by ioa747

I know that I know nothing

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...