poweeshell 按比例处理的- Function Script:Imagefile
- {
- param([String]$ph=$env:TEMP,[Int]$lity=90,[String]$str = "A2 文件`n")
- Begin {
- $ph += "\new_files\"
- $ph
- if (![System.IO.Directory]::Exists($ph)) {$null = New-Item $ph -type directory}
- Add-Type -AssemblyName "System.Drawing"
- $ima = [System.Drawing.Imaging.Encoder]::Quality
- $enc = New-Object System.Drawing.Imaging.EncoderParameters(1)
- $enc.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter($ima, $lity)
- $Code = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where {$_.MimeType -eq 'image/jpeg'}
- }
- process
- {
- $saveFile = Join-Path -Path $ph -ChildPath ($_.BaseName + '_' + $(Get-Date -Format "yyyyMMddHHmmssfff") + $_.Extension)
- $img = [System.Drawing.Image]::FromFile($_)
- $width = $img.Width
- $height = $img.Height
- if ($width -gt 3900 -or $height -gt 3900) {
- if ($width -gt 5300 -or $height -gt 5300) {
- $str = $str + "$_" + "`n"
- }else {$m = 4960 / [Math]::Max($width,$height)}
- }else {$m = 3507 / [Math]::Max($width,$height)}
- $w =[int] ($width * $m)
- $h =[int] ($height * $m)
- $size = New-Object System.Drawing.Bitmap($w, $h)
- $tmp = [System.Drawing.Graphics]::FromImage($size)
- $tmp.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
- $tmp.Clear([System.Drawing.Color]::White)
- $tmp.DrawImage($img, 0, 0, $w, $h)
- $size.Save($saveFile, $Code, $($enc))
- $img.Dispose()
- $size.Dispose()
- $tmp.Dispose()
- }
- end
- {
- $str
- start "$ph"
- }
- }
-
- $ph = $pwd.Path
- Get-ChildItem .\ *.jpg|?{!$_.PsIsContainer}| Imagefile -ph $ph -lity 60 -str "A2"
复制代码
|