AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Finding the width/height of a picture

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
justcallmedrago



Joined: 23 Jun 2006
Posts: 46

PostPosted: Fri Oct 06, 2006 8:09 pm    Post subject: Finding the width/height of a picture Reply with quote

is there any way to get the dimensions of a picture without putting it onto a gui?
Back to top
View user's profile Send private message Send e-mail
slomz



Joined: 03 Sep 2006
Posts: 608
Location: Iowa, U.S.

PostPosted: Fri Oct 06, 2006 9:22 pm    Post subject: Reply with quote

ControlGetPos
Back to top
View user's profile Send private message AIM Address
SKAN



Joined: 26 Dec 2005
Posts: 5790

PostPosted: Fri Oct 06, 2006 9:37 pm    Post subject: Re: Finding the width/height of a picture Reply with quote

justcallmedrago wrote:
is there any way to get the dimensions of a picture without putting it onto a gui?


You have to rely on a command line utility or there maybe a third party DLL for that..

If you want to do it with pure AHK you have to write seperate routines for
each image file type..

Post again if you can manage with a command line utility..

Regards, Smile
_________________
SKAN - Suresh Kumar A N
Back to top
View user's profile Send private message
silveredge78



Joined: 25 Jul 2006
Posts: 378
Location: Midwest, USA

PostPosted: Fri Oct 06, 2006 11:44 pm    Post subject: Reply with quote

Irfanview to the rescue! Gotta love the command line utility. You will want to use the /info and /killmesoftly commands. To illustrate what the output looks like:

Irfanview Info Output wrote:
[test.jpg]
File name = test.jpg
Directory = C:\
Compression = JPEG/JFIF
Resolution = 96 x 96 DPI
Image dimensions = 160 x 160 Pixels
Print size = 4.2 x 4.2 cm; 1.7 x 1.7 inches
Color depth = 16,7 Millions (24 BitsPerPixel)
Number of unique colors = 8594
Disk size = 4.73 KB (4,847 Bytes)
Current memory size = 75.04 KB (76,840 Bytes)
File date/time = 2/28/2006 / 19:50:21

So try something like:

Code:
File = c:\*.jpg
Info = c:\infojpg.txt

Run, %A_ProgramFiles%\Irfanview\i_view32.exe %File% /info=%Info% /killmesoftly
Sleep, 500
Loop, Read, %Info%
{
  If A_LoopReadLine Contains [
  {
    StringTrimLeft, FileName, A_LoopReadLine, 1
    StringTrimRight, FileName, FileName, 1
  }
  Else If A_LoopReadLine Contains Image dimensions
  {
    StringTrimLeft, Dimensions, A_LoopReadLine, 19
    MsgBox, The dimensions of %FileName% are %Dimensions%.
  }
}
Return

_________________
SilverEdge78
Back to top
View user's profile Send private message
Paulo



Joined: 21 Apr 2006
Posts: 28
Location: Brazil

PostPosted: Sat Oct 07, 2006 5:49 pm    Post subject: Reply with quote

You can also use Philho's image functions http://www.autohotkey.com/forum/viewtopic.php?t=11860 and add a new function to GDIplusWrapper.ahk to get the dimensions of some image.
This code returns the dimensoins Widthxheight in pixels as floating point numbers separated by "|"
Code:
GetImageDimension(_image)
{
   DllCall("GDIplus\GdipGetImageDimension"
         , "UInt", _image
         , "Float*", w
         , "Float*", h)
   Return w "|" h
}


note:
You may want to add Philho's error checking routine...

To call this function:
Code:

#Include GDIplusWrapper.ahk

fileName = path to your pic

If (GDIplus_Start() != 0)
   Goto g_GDI_Error
If (GDIplus_LoadBitmap(bitmap, fileName) != 0)
   Goto g_GDI_Error
MsgBox, % GDIplus_GetImageDim(bitmap)
GDIplus_Stop()
Return

g_GDI_Error:
   If (#GDIplus_lastError != "")
      MsgBox 16, GDIplus Test, Error in %#GDIplus_lastError%
   GDIplus_Stop()
Return
Back to top
View user's profile Send private message
Flytox
Guest





PostPosted: Tue Dec 19, 2006 4:59 am    Post subject: Reply with quote

I know of the great stupidity of my solution, but to get a picture dimensions, i just type:

run "c:\program files\irfanview\i_view32.exe" %SourceFolder%\%PictureName% /info=%clipboardAll%\InfoPic.txt

Then FileReadLine and StringSplit
Back to top
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue Dec 19, 2006 9:50 am    Post subject: Reply with quote

That's exactly the solution given by silveredge78, which provides the code...
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
BoBo
Guest





PostPosted: Tue Dec 19, 2006 11:02 am    Post subject: Reply with quote

EXIF ?
Back to top
PhiLho



Joined: 27 Dec 2005
Posts: 6721
Location: France (near Paris)

PostPosted: Tue Dec 19, 2006 11:39 am    Post subject: Reply with quote

BoBo wrote:
EXIF ?
Only for Jpeg, AFAIK.
Not sure what you mean, actually... You want to get Exif info from an image?
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
Lemming



Joined: 20 Dec 2005
Posts: 150
Location: Malaysia

PostPosted: Thu Jun 28, 2007 2:46 pm    Post subject: kludge but it works Reply with quote

I also had to query image dimensions a few days ago. I ended going with IrfanView too.

While I'm sure GDIplusWrapper would have been more elegant, it seems like overkill to get one piece of info (nothing personal, PhiLho Wink

So I just modded silveredge78's script a bit, with minor error handling and file cleanup. Plus, I'm using FileRead and RegexMatch instead:

Code:
File = sample.jpg
Info = infojpg.txt

IfExist, %Info%
   {
   FileDelete, %Info% ; del any existing file
   Sleep, 100
   }
Run, %A_ProgramFiles%\Irfanview\i_view32.exe %File% /info=%Info% /killmesoftly
Sleep, 100
IfNotExist, %Info%
   Sleep, 200 ; pause a bit
FileRead, ImgInfo, %Info%
UnusedVar := RegExMatch(ImgInfo, "sions = (\d{2,5}) x (\d{2,5})", Side)  ; Returns Side1 and Side2
MsgBox, Image size is:`n`n %Side1% x %Side2% (W x H)
FileDelete, %Info% ; clean up after ourselves


The regex assumes img dimension range is 10-99999. Change if required.
Back to top
View user's profile Send private message
Klaus



Joined: 12 May 2005
Posts: 190
Location: Münster, Germany

PostPosted: Wed Sep 05, 2007 12:51 pm    Post subject: Reply with quote

Hi, justcallmedrago,
even though slomz was faster, now that I've put together an example, I'll post:


Code:
Gui, Add, Picture, vpicture, {some graphic file here}
Gui, Add, Button, vbutton ggetSize, Size
Gui, Show
return

getSize:
ControlGetPos, x, y, w, h, Static1
MsgBox, Size of the picture`n`nWidth  %w%  `n Height %h%
return
Just let it happen in an hidden gui, if you don't want to see anything happen.

Regards,
Klaus

To be honest:
Someone here in the forum (don't know who) provided me the above answer to the same question like yours!
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group