AutoHotkey Community

It is currently May 27th, 2012, 11:10 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: January 22nd, 2012, 10:49 am 
Offline

Joined: August 29th, 2011, 10:35 pm
Posts: 30
Location: Tokyo
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.

_________________
English teachers are welcome.


Last edited by A_Samurai on January 22nd, 2012, 2:54 pm, edited 2 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject: Re: GetImageDimensions()
PostPosted: January 22nd, 2012, 12:44 pm 
Offline

Joined: August 7th, 2011, 1:23 pm
Posts: 754
A_Samurai wrote:
Code:
      Loop
         DimensionIndex := A_Index
      Until (objFolder.GetDetailsOf(objFolder.Items, A_Index) = "dimensions")   

What about if your code does never find the string dimensions, for example in a localized OS version (italian in my case ).
IT WILL LOOP FOREVER!!! ( ~20% of CPU ).
You must pay attention on that.

P.S: changing the string to italian your code works.

_________________
Win7 - Firefox 10.0.2 - AHK_L 1.1.07.00
Please bear with me and my English which is so bad at times that even I don't understand myself


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: January 22nd, 2012, 1:08 pm 
Offline

Joined: August 29th, 2011, 10:35 pm
Posts: 30
Location: Tokyo
Ops, updated.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: Exabot [Bot], iDrug, nomissenrojb, Rajat and 55 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group