我在这里使用此脚本来检查图片是否大于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")
关于powershell - 如果图片大于,如何调整图片大小,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45453148/