Jump to content

Recommended Posts

Posted

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.

 

Posted
Posted
On 7/19/2024 at 9:53 PM, Andreik said:

Check in help file _GDIPlus_ImageGetDimension(). There is also an example.

Unfortunately this doesn't work with JP2 (jpeg2000) files.

Posted
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. 

  • 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

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
×
×
  • Create New...