 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
justcallmedrago
Joined: 23 Jun 2006 Posts: 46
|
Posted: Fri Oct 06, 2006 8:09 pm Post subject: Finding the width/height of a picture |
|
|
| is there any way to get the dimensions of a picture without putting it onto a gui? |
|
| Back to top |
|
 |
slomz
Joined: 03 Sep 2006 Posts: 608 Location: Iowa, U.S.
|
Posted: Fri Oct 06, 2006 9:22 pm Post subject: |
|
|
| ControlGetPos |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 5790
|
Posted: Fri Oct 06, 2006 9:37 pm Post subject: Re: Finding the width/height of a picture |
|
|
| 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,  _________________ SKAN - Suresh Kumar A N |
|
| Back to top |
|
 |
silveredge78
Joined: 25 Jul 2006 Posts: 378 Location: Midwest, USA
|
Posted: Fri Oct 06, 2006 11:44 pm Post subject: |
|
|
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 |
|
 |
Paulo
Joined: 21 Apr 2006 Posts: 28 Location: Brazil
|
Posted: Sat Oct 07, 2006 5:49 pm Post subject: |
|
|
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 |
|
 |
Flytox Guest
|
Posted: Tue Dec 19, 2006 4:59 am Post subject: |
|
|
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)
|
Posted: Tue Dec 19, 2006 9:50 am Post subject: |
|
|
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 |
|
 |
BoBo Guest
|
Posted: Tue Dec 19, 2006 11:02 am Post subject: |
|
|
| EXIF ? |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6721 Location: France (near Paris)
|
Posted: Tue Dec 19, 2006 11:39 am Post subject: |
|
|
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 |
|
 |
Lemming
Joined: 20 Dec 2005 Posts: 150 Location: Malaysia
|
Posted: Thu Jun 28, 2007 2:46 pm Post subject: kludge but it works |
|
|
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
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 |
|
 |
Klaus
Joined: 12 May 2005 Posts: 190 Location: Münster, Germany
|
Posted: Wed Sep 05, 2007 12:51 pm Post subject: |
|
|
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 |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|