Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

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 powershellcommunity.org 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.