紧跟着这个Smart image search via Powershell
我有以下PowerShell脚本:-
Add-Type -Assembly System.Drawing
function Get-Image {
$input | ForEach-Object { [Drawing.Image]::FromFile($_.FullName) }
}
Get-ChildItem -Path 'C:\Images' -Filter *.jpg -Recurse | Get-Image | ? { $_.Width -gt 1280 -or $_.Height -gt 1280 }
问题是,这将返回一个Image对象列表。
我基本上想要一个宽度或高度大于1280像素的文件对象(最终将是图像)列表。
我需要以某种方式将图像对象转换回文件对象吗?
最后通is是大于1280像素的文件名列表。
最佳答案
function Get-Image{
process {
$file = $_
[Drawing.Image]::FromFile($_.FullName) |
ForEach-Object{
$_ | Add-Member -PassThru NoteProperty FullName ('{0}' -f $file.FullName)
}
}
}
然后
Get-ChildItem -Path 'C:\Images' -Filter *.jpg -Recurse | Get-Image | ? { $_.Width -gt 1280 -or $_.Height -gt 1280 } | select -expa Fullname | get-item
关于.net - 使用PowerShell将具有特定尺寸的图像文件列表作为文件对象获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13741668/