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



我这里有这个脚本来检查图片是否大于 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 Image Acquisition (来实现此目的:

$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")

相关内容

  • 没有找到相关文章

最新更新