.net - 使用PowerShell将具有特定尺寸的图像文件列表作为文件对象获取

标签 .net powershell imagemagick

紧跟着这个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/

相关文章:

c# - EntityType 'Worker' 没有定义键。定义此 EntityType 的键

powershell - 如何在Powershell中基于多个匹配字段值创建数据子集?

powershell - Powershell 中的多个管道

c - ImageMagick逐行(或逐 strip )写入图像文件

c# - 使用反射获取继承接口(interface)的类的属性

c++ - 将 C++ 库移植到 .NET

ruby-on-rails - 回形针 422 错误

php - 使用 PHP 从 .pdf 中提取页面

C# 线程在第二个线程上崩溃,不确定如何修复

powershell - 是否可以使用 F# 创建 Windows PowerShell Cmdlet?