Image Dimension ??

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
spam_killer
Posts: 12
Joined: 10 Oct 2008 04:50

Image Dimension ??

#1 Post by spam_killer » 01 May 2009 13:52

Is there any trick or command line to get the dimension of an image such as jpg or gif using CMD command..

I search this forum for any topic related to the problem but I can't find any solution.. Also search in google but still no result..

If there is not possible to get image dimension from command line, can anyone suggest any software available on the internet?


Thanks..!!

jaffamuffin
Posts: 40
Joined: 25 Jan 2008 14:05

#2 Post by jaffamuffin » 04 May 2009 10:17

ImageMagick is a fantastic command line program and will give you thousands of operations possible on images.

But "identify image.jpg" should out put the required info, just use a for loop to extract the required values.


Also, XP has built in functionally (like how explorer can give you details of the file size in details view)

Possibly using the post below about dll integration it may be possible, or using a bit of vba. there is a post on the imagemagick forums about this but I can't find it just now, complete with vba code.

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Image Dimension ??

#3 Post by npocmaka_ » 26 Jan 2015 08:42

tooltipInfo.bat:

Code: Select all

@if (@X)==(@Y) @end /* JScript comment
   @echo off
   
   rem :: the first argument is the script name as it will be used for proper help message
   cscript //E:JScript //nologo "%~f0" %*

   exit /b %errorlevel%
   
@if (@X)==(@Y) @end JScript comment */
 
//////
FSOObj = new ActiveXObject("Scripting.FileSystemObject");
var ARGS = WScript.Arguments;
if (ARGS.Length < 1 ) {
 WScript.Echo("No file passed");
 WScript.Quit(1);
}
var filename=ARGS.Item(0);
var objShell=new ActiveXObject("Shell.Application");
/////


//fso
ExistsItem = function (path) {
   return FSOObj.FolderExists(path)||FSOObj.FileExists(path);
}

getFullPath = function (path) {
    return FSOObj.GetAbsolutePathName(path);
}
//

//paths
getParent = function(path){
   var splitted=path.split("\\");
   var result="";
   for (var s=0;s<splitted.length-1;s++){
      if (s==0) {
         result=splitted[s];
      } else {
         result=result+"\\"+splitted[s];
      }
   }
   return result;
}


getName = function(path){
   var splitted=path.split("\\");
   return splitted[splitted.length-1];
}
//

function main(){
   if (!ExistsItem(filename)) {
      WScript.Echo(filename + " does not exist");
      WScript.Quit(2);
   }
   var fullFilename=getFullPath(filename);
   var namespace=getParent(fullFilename);
   var name=getName(fullFilename);
   var objFolder=objShell.NameSpace(namespace);
   var objItem=objFolder.ParseName(name);
   //https://msdn.microsoft.com/en-us/library/windows/desktop/bb787870(v=vs.85).aspx
   WScript.Echo(fullFilename + " : ");
   WScript.Echo(objFolder.GetDetailsOf(objItem,-1));
   
}

main();


It accepts single argument - the file and prints it's toop tip info.Used against picture:

C:\Capture.PNG :
Item type: PNG image
Dimensions: ?871 x 836?
Size: 63.8 KB


For binaries it will print their version, for media files their length and etc.

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Image Dimension ??

#4 Post by npocmaka_ » 25 Apr 2015 03:18

Another way - with WIA.ImageFile object:


Code: Select all

@if (@X)==(@Y) @end /* JScript comment
   @echo off
   
   rem :: the first argument is the script name as it will be used for proper help message
   cscript //E:JScript //nologo "%~f0" %*

   exit /b %errorlevel%
   
@if (@X)==(@Y) @end JScript comment */

FSOObj = new ActiveXObject("Scripting.FileSystemObject");
var ARGS = WScript.Arguments;
if (ARGS.Length < 1 ) {
 WScript.Echo("No file passed");
 WScript.Echo("Usage:");
 WScript.Echo(" Image");
 WScript.Quit(1);
}
var filename=ARGS.Item(0);

if (!FSOObj.FileExists(filename)){
   WScript.Echo("File "+filename+" does not exists");
   WScript.Quit(2);
}
try {
   var img=new ActiveXObject("WIA.ImageFile");
}catch(err){
   WScript.Echo("Probably "+ filename + " is not an image");
   WScript.Echo(err.message);
   WScript.Quit(3);
   
}
img.LoadFile(filename);
WScript.Echo("Height:"+img.Height);
WScript.Echo("Width:"+img.Width);
WScript.Echo("HorizontalResolution:"+img.HorizontalResolution);
WScript.Echo("VerticalResolution:"+img.VerticalResolution);
WScript.Echo("Format:"+img.FormatID);
WScript.Echo("ActiveFrame:"+img.ActiveFrame);
WScript.Echo("Type:"+img.FileExtension);
WScript.Echo("FrameCount:"+img.FrameCount);
WScript.Echo("IsAnimated:"+img.IsAnimated);
WScript.Echo("PixelDepth:"+img.PixelDepth);
WScript.Echo("IsExtendedPixelFormat:"+img.IsExtendedPixelFormat);
WScript.Echo("IsAlphaPixelFormat:"+img.IsAlphaPixelFormat);


With Wia.ImageProcess is possible to edit pictures -

Code: Select all

 https://msdn.microsoft.com/en-us/library/windows/desktop/ms630826(v=vs.85).aspx#SharedSample007
https://msdn.microsoft.com/en-us/library/windows/desktop/ms630819(v=vs.85).aspx
Last edited by npocmaka_ on 26 Apr 2015 05:50, edited 2 times in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Image Dimension ??

#5 Post by foxidrive » 25 Apr 2015 06:57

I'm curious what the resolution figures represent....

Height:769
Width:1066
HorizontalResolution:143.9925994873047
VerticalResolution:143.9925994873047
Format:{B96B3CAF-0728-11D3-9D7B-0000F81EF32E}
ActiveFrame:1
Type:png
FrameCount:1
IsAnimated:false
PixelDepth:24
IsExtendedPixelFormat:false
IsAlphaPixelFormat:false

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Image Dimension ??

#6 Post by npocmaka_ » 25 Apr 2015 07:23

Code: Select all

https://msdn.microsoft.com/en-us/library/windows/desktop/ms630506%28v=vs.85%29.aspx?f=255&MSPPError=-2147217396

pixels per inch/dpi. I prefer pixels...

Post Reply