Steveiwonder Posted January 19, 2010 Share Posted January 19, 2010 (edited) Hey All, How can i get Height / Width of an image in pixels? Searched and found this post: http://www.autoitscript.com/forum/index.php?showtopic=28746 Which led me too this post: http://www.autoitscript.com/forum/index.php?showtopic=25859 How ever that function doesnt seem to work: #include <ExtProp.au3> $width = _GetExtProperty("C:\Users\Steveiwonder\Pictures\Untitled.png", 27) $height = _GetExtProperty("C:\Users\Steveiwonder\Pictures\Untitled.png", 28) ConsoleWrite($width & @CRLF) ConsoleWrite($height & @CRLF) Output this: >"C:\Program Files (x86)\AutoIt3\SciTE\..\autoit3.exe" /ErrorStdOut "C:\Users\Steveiwonder\Desktop\New AutoIt v3 Script.au3" 0 0 >Exit code: 0 Time: 0.337 Looking at the post it was last edited @ "This post has been edited by Simucal: 27 July 2006 - 06:55 PM " So im getting its not up to date. Is there any better way to get these properties of an image file? I've had a look at the help file but not getting anywhere. Appreciate any help. Thanks. Steve. Edited January 19, 2010 by Steveiwonder They call me MrRegExpMan Link to comment Share on other sites More sharing options...
Mat Posted January 19, 2010 Share Posted January 19, 2010 (edited) #Include <GDIPlus.au3> _GDIPlus_Startup () Local $hImage = _GDIPlus_ImageLoadFromFile("C:\Users\Steveiwonder\Pictures\Untitled.png") If @error Then MsgBox(16, "Error", "Does the file exist?") Exit 1 EndIf ConsoleWrite(_GDIPlus_ImageGetWidth($hImage) & @CRLF) ConsoleWrite(_GDIPlus_ImageGetHeight($hImage) & @CRLF) _GDIPlus_ImageDispose ($hImage) _GDIPlus_ShutDown () Edited January 19, 2010 by Mat krasnoshtan and ahmeddzcom 1 1 AutoIt Project Listing Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 19, 2010 Moderators Share Posted January 19, 2010 Steveiwonder,This code works for me:$sPassed_File_Name = "Fred.PNG" Local $sDir_Name = StringRegExpReplace($sPassed_File_Name, "(^.*\\)(.*)", "\1") Local $sFile_Name = StringRegExpReplace($sPassed_File_Name, "^.*\\", "") Local $sDOS_Dir = FileGetShortName($sDir_Name, 1) Local $oShellApp = ObjCreate("shell.application") If IsObj($oShellApp) Then Local $oDir = $oShellApp.NameSpace($sDOS_Dir) If IsObj($oDir) Then Local $oFile = $oDir.Parsename($sFile_Name) If IsObj($oFile) Then ConsoleWrite($oDir.GetDetailsOf($oFile, 31) & @CRLF) Else $iError = 3 EndIf Else $iError = 2 EndIf Else $iError = 1 EndIfIt gives me ?567 x 282? as an output - needs a bit of formatting, but it is correct. The value 31 should work in Vista and Win 7 - in XP use 26.I hope this helps. M23 krasnoshtan 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
wakillon Posted September 6, 2010 Share Posted September 6, 2010 (edited) $sPassed_File_Name = 'D:\Wallpapers\NEW\minhkoi.net-813-06.jpg' Local $sDir_Name = StringRegExpReplace($sPassed_File_Name, "(^.*\\)(.*)", "\1") Local $sFile_Name = StringRegExpReplace($sPassed_File_Name, "^.*\\", "") Local $sDOS_Dir = FileGetShortName($sDir_Name, 1) Local $oShellApp = ObjCreate ( "shell.application" ) If IsObj ( $oShellApp ) Then Local $oDir = $oShellApp.NameSpace ( $sDOS_Dir ) If IsObj ( $oDir ) Then Local $oFile = $oDir.Parsename ( $sFile_Name ) If IsObj ( $oFile ) Then For $_I = 1 To 35 $_Details = $oDir.GetDetailsOf ( $oFile, $_I ) If $_Details <> '' Then ConsoleWrite ( $_I & ' : ' & $_Details & @CRLF) Next Else $iError = 3 EndIf Else $iError = 2 EndIf Else $iError = 1 EndIfOn XP It give this1 : 334 KB2 : Image JPEG3 : 15/03/2007 13:244 : 23/06/2010 20:325 : 15/07/2010 22:476 : A7 : Connecté8 : 334 KB12 : S-1-5-21-725345543-362288127-1177238915-50017 : 130 : 1680 x 105031 : 1680 pixels32 : 1050 pixels35 : 2007:03:15 13:24:41Now I know why I obtain different result than bovanshi on his post ! Edited September 7, 2010 by wakillon AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
KaFu Posted September 6, 2010 Share Posted September 6, 2010 This one by Lazycat works fine too using winapi dllcalls. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2024-Oct-20) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
Malkey Posted September 7, 2010 Share Posted September 7, 2010 The three results that differ having run wakillon's script on my XP are:- 26 : w x h 27 : w pixels 28 : h pixels wakillon's results on XP: 30 : w x h 31 : w pixels 32 : h pixels Melba23's equivalent result on Vista and Win 7 (8 months ago): 31 : w x h Melba23's equivalent result on XP: 26 : w x h (same as mine) It appears this "object.GetDetailsOf()" method to obtain an image's size is subject to error. Test this _ImageSize() function. It is a stand alone function using gdiplus dllcalls, and works fine on my XP. ; Local $FullFileName = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\logo4.gif" ;Local $FullFileName = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt", "InstallDir") & "\Examples\GUI\sampleAVI.avi" Local $a = _ImageSize($FullFileName) If @error Then MsgBox(0, "Results", '"' & $FullFileName & '" file does not exist, or is not a valid image file.') Else MsgBox(0, "Results", '"' & $FullFileName & '" - Size: ' & $a[0] & " x " & $a[1]) EndIf ; Returns Array[0] - width of image. ; Array[1] - heigth of image. Func _ImageSize($sFileName) Local $aRet[2], $sExt = StringRegExpReplace($sFileName, "^.*\.", "") If (FileExists($sFileName) = 0) Or _ ((StringLen($sExt) = 3) And (StringRegExp($sExt, "(?i)(bmp|gif|jpg|png|tif|emf|wmf)") = 0)) Or _ ((StringLen($sExt) = 4) And (StringRegExp($sExt, "(?i)(tiff|jpeg)") = 0)) Then _ Return SetError(1, 0, $aRet) Local $ghGDIPDll = DllOpen("GDIPlus.dll") Local $tInput = DllStructCreate("int Version;ptr Callback;int NoThread;int NoCodecs") Local $tToken = DllStructCreate("ulong_ptr Data") DllStructSetData($tInput, "Version", 1) DllCall($ghGDIPDll, "int", "GdiplusStartup", "ptr", DllStructGetPtr($tToken), "ptr", DllStructGetPtr($tInput), "ptr", 0) Local $aImage = DllCall($ghGDIPDll, "int", "GdipLoadImageFromFile", "wstr", $sFileName, "ptr*", 0) Local $aResult = DllCall($ghGDIPDll, "int", "GdipGetImageWidth", "handle", $aImage[2], "uint*", -1) $aRet[0] = $aResult[2] $aResult = DllCall($ghGDIPDll, "int", "GdipGetImageHeight", "handle", $aImage[2], "uint*", 0) $aRet[1] = $aResult[2] DllCall($ghGDIPDll, "int", "GdipDisposeImage", "handle", $aImage[2]) DllCall($ghGDIPDll, "none", "GdiplusShutdown", "ptr", DllStructGetData($tToken, "Data")) DllClose($ghGDIPDll) Return SetError(0, 0, $aRet) EndFunc ;==>_ImageSize PoojaKrishna 1 Link to comment Share on other sites More sharing options...
wakillon Posted September 7, 2010 Share Posted September 7, 2010 This one by Lazycat works fine too using winapi dllcalls.Thanks KaFu and Malkey your 2 functions works fine ! AutoIt 3.3.14.2 X86 - SciTE 3.6.0 - WIN 8.1 X64 - Other Example Scripts Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now