答案1
使用以下PowerShell脚本,然后sorted.csv
使用Excel打开,并根据需要执行进一步的操作。
测试.ps1:
$image = New-Object -ComObject Wia.ImageFile
echo ("Name,Width,Height,Area") > test.csv
dir *.png | foreach {
$fname =$_.FullName
$image.LoadFile($fname)
$area=$image.Width*$image.Height
echo ('"'+$fname+'",'+$image.Width+","+$image.Height+","+$area)
} >> test.csv
# sort the csv by area (ascending)
Import-Csv test.csv | sort Area | Export-Csv -Path sorted.csv -NoTypeInformation
笔记:
- 使用Wia.图像文件Com 对象。
test.csv
包含未分类的输出sorted.csv
包含按“区域”排序(升序)的输出(Width
*Height
)
示例输出:
PS F:\test> dir *.png
Directory: F:\test
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 01/09/2015 11:45 27156 1.png
-a---- 01/09/2015 11:46 17900 2.png
-a---- 21/05/2015 14:40 114304 3.png
-a---- 15/04/2015 12:56 429394 4.png
PS F:\test> .\test.ps1
PS F:\test> type test.csv
Name,Width,Height,Area
"F:\test\1.png",869,532,462308
"F:\test\2.png",870,344,299280
"F:\test\3.png",328,328,107584
"F:\test\4.png",546,494,269724
PS F:\test> type sorted.csv
"Name","Width","Height","Area"
"F:\test\3.png","328","328","107584"
"F:\test\4.png","546","494","269724"
"F:\test\2.png","870","344","299280"
"F:\test\1.png","869","532","462308"
进一步阅读
- Windows PowerShell 博客:PowerShell 中的图像处理