Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am having many image files in one folder. Mostly there are jpg, but some png, bmp, gif, tif also (but jpg is most important if others are not possible). There are also many xml files in same folder with same names as image files are having. So there is something like this: 1.jpg, 1.xml, a.png, a.xml, 3g.bmp, 3g.xml...

All xml files are having only 1 line: <IMGRES WIDTH="1234" HEIGHT="567" /> (of course numbers are not same).

I am looking for some easy way to check all image sizes and confirm if they are same as in xml or not. So I want output like:

imagename, xmlwidth x xmlheight, realwidth x realheight, match/error

Is this possible in only Windows with no other software installed?

share|improve this question
Scripting is not a strength of Windows, solving a task like this would be a breeze in Linux. – Stefan Seidel Sep 18 '12 at 7:21

Rather than compare them, I'd write a script to recreate the XML files from the output of a tool such as ImageMagick's identify

I'd start with something like

 for %f in (*.*) do ^
    identify -format '<IMGRES WIDTH="%w" HEIGHT="%h" />' %f% > %f%.xml

Then fix up the filename extension handling etc etc.

To do a comparison as you ask, I'd use a better scripting language (Perl in my case, but I expect many other people would use the built-in powershell)

You could use the code above but write the output to a fixed filename and then use fcand if in the for-loop to generate your desired output.

To do what you ask using only built-in tools I'd look at powershell.

Here is an example from which you could use as a starting point.

function _Get-ImageStream 
param ($File) 

$image = [System.Drawing.Image]::FromFile($File) 
$imageStream = New-Object System.IO.MemoryStream 
$image.Save($imageStream, [System.Drawing.Imaging.ImageFormat]::Jpeg) 

return $imageStream 

[System.Reflection.Assembly]::LoadFile( "C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll") 

"Name|SizeInBytes|Width|Height" >> C:\JPGInfo.txt 

$path = "C:\Images\" 
$imageFiles = Get-ChildItem -Recurse $path -Include *.jpg 

foreach ($image in $imageFiles) 
$name = $image.Name 
$length = $image.Length 
$imageStream = _Get-ImageStream -File $image.FullName 
$width = $imagestream.Width 
$height = $imageStream.Height 

"$name|$length|$width|$height" >> C:\JPGInfo.txt 
share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .