如果图片大于,如何调整图片大小

how to resize pictures if they are greater than

我这里有这个脚本来检查图片是否大于 1024x768。然后如何将这些图片调整为 1024x768?

function Get-Image{ 
process {
          $file = $_
          [Drawing.Image]::FromFile($_.FullName)  |
          ForEach-Object{           
            $_ | Add-Member -PassThru NoteProperty FullName ('{0}' -f $file.FullName)
          }
         }
}    
Get-ChildItem -Path 'E:\Parts' -Filter *.jpg -Recurse | Get-Image | ? { $_.Width -gt 1024 -or $_.Height -gt 768 } | select -expa Fullname | get-item

您可以为此使用 WIA(Windows 图像采集):

$wia = New-Object -com wia.imagefile
$wia.LoadFile("d:\tobi.jpg")
$wip = New-Object -ComObject wia.imageprocess
$scale = $wip.FilterInfos.Item("Scale").FilterId                    
$wip.Filters.Add($scale)
$wip.Filters[1].Properties("MaximumWidth") = 1024
$wip.Filters[1].Properties("MaximumHeight") = 768
#aspect ratio should be set as false if you want the pics in exact size 
$wip.Filters[1].Properties("PreserveAspectRatio") = $false
$wip.Apply($wia) 
$newimg = $wip.Apply($wia)
$newimg.SaveFile("d:\tobi0.jpg")