2017-08-02 83 views
2

我有這裏的腳本來檢查圖片是否大於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 
+0

蘭索斯取樣是簡單的圖像大小調整的常用方法。 – bipll

回答

0

可以使用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") 
相關問題