Script to get images in folder with dimensions printed to a .txt file
Solution 1
Using ExifTool (portable executable renamed to exiftool.exe):
exiftool -ImageSize -r .
Here ImageSize is the tag name you're interested in and will print Image Width x Image Height. The -r
switch makes it recursively process files in subdirectories.
Custom output string format is simple as well. For example:
exiftool -p "Image Name: \"$FileName\"$/Image Size: $ImageSize$/" -r .
In this case the tag names are preceded by $. $/
prints a newline.
Note: The commands above have to be typed at the command prompt. To redirect the output to a text file you can append > Details.txt
to them.
If you want to simply run the program and have it write a text file with the relevant image details, you can rename the executable as follows:
ExifTool(-FileName -Imagesize -w+! %0fDetails.txt -ext gif --ext exe .).exe
This will write all console output (-w
) to a file named Details.txt in the current directory. In this case the output will consist of the image names and sizes for all GIFs in the current directory. Further details about the -w
parameter, including the meaning of +
, !
and %0f
are available at the documentation link above.
You can include more extensions to be processed using -ext jpg -ext png
and so on, or delete -ext gif
altogether to make it read all supported file types (including non-images which you may not want).
--ext exe
is used to exclude all EXEs (so that the program's own executable isn't included in the report).
-r
can of course be added to enable recursive processing.
There is lots more you can do with the program given how ridiculously powerful it is (and extensible too given that the full Perl source is freely available)!
Solution 2
Ok solution with ImageMagick, simple and quick (but ofc requires the library).
Open the cmd line in the folder you are interested (Shift+RightClick inside your folder window and select "Open command window here"), then in the cmd prompt use this
identify -format "%f %wx%h\r" *.jpg > info.txt
Calls for %f filename
, %w width
and %h height
formatted like "WIDTHxHEIGHT"
More info here http://www.imagemagick.org/script/escape.php
Solution 3
There a PowerShell script below that should do it; just change the directories for list and output. I tested under Windows 8.1 and Windows PowerShellISE.
param( $folder = "E:\My Pictures", $outputFile = "E:\details.txt" )
$objShell = New-Object -ComObject Shell.Application
$fileList = @()
$attrList = @{}
$details = ( "Dimensions" )
$objFolder = $objShell.namespace($folder)
for ($attr = 0 ; $attr -le 500; $attr++)
{
$attrName = $objFolder.getDetailsOf($objFolder.items, $attr)
if ( $attrName -and ( -not $attrList.Contains($attrName) ))
{
$attrList.add( $attrName, $attr )
}
}
dir $folder -Recurse -Directory | ForEach-Object{
$objFolder = $objShell.namespace($_.FullName)
foreach($file in $objFolder.items())
{
foreach( $attr in $details)
{
$attrValue = $objFolder.getDetailsOf($file, $attrList[$attr])
if ( $attrValue )
{
Add-Member -InputObject $file -MemberType NoteProperty -Name $("A_" + $attr) -value $attrValue
}
}
$fileList += $file
$fileList.Count
}
}
$fileList | Export-Csv $outputFile -Delimiter ','
$fileList | Format-Table
Related videos on Youtube
Gruber
Updated on September 18, 2022Comments
-
Gruber over 1 year
As title goes, is there a script for Win 7 to get printed on a .txt file all the images (JPG, PNG, GIF ecc) inside a folder along with "filename" and "pixels dimension"?
I've tried withdir
on command line but only lists name, file size ecc..
Solution with ExifTool
The best deal imo, with the command already coded in the file name of the .exe its totally a drag and drop script to use wherever you want!
Update
For convenience, I've slightly modified the inline file name of the exe to thisExifTool(-FileName -Imagesize -r -T -w+! %0finfo.txt -ext jpg --ext exe .).exe
This way I've reduced to the minimum the .txt output to a single line per image (
-T
) and added a recursive option (-r
) so that it can process subfolders too.
Solution with ImageMagick
I've placed below my solution with ImageMagick, is pretty quick and simple but ofc requires the library installed.
-
Gruber almost 9 yearsThis is not working since you set the folders. I'd like to have it works in whatever folder I drop the file script to. How can this be modified?
-
Gruber almost 9 yearsLooks interesting but I'm a bit stuck using it, I've been able to make it output the sizes inside the command window only after I've opened the images with drag-drop. How can I make it create a .txt file with the output? How can I simply drop the .exe in the folder double click and do the magic? Thank you for your answer
-
Karan almost 9 years@Gruber: Those commands actually have to be typed at the command prompt. To redirect to a text file you can add
> Details.txt
to the end of the commands. I have a far better one-click solution for your problem however. See the edited answer above. -
Gruber almost 9 yearsNow that's amazing! Thank you for extending your answer with the script in the .exe file name, ridiculously handy! :)
-
DrMoishe Pippik almost 9 yearsUse ".' for the current directory, so line 1 becomes: param( $folder = ".", $outputFile = "details.txt" )
-
Karan almost 9 years@Gruber: You're welcome, glad you found it useful. :)