[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
处理后感觉是拉伸效果而不是缩放效果

TOP

poweeshell 按比例处理的
  1. Function Script:Imagefile
  2. {
  3. param([String]$ph=$env:TEMP,[Int]$lity=90,[String]$str = "A2 文件`n")
  4.     Begin {
  5.         $ph +=  "\new_files\"
  6.         $ph
  7.         if (![System.IO.Directory]::Exists($ph)) {$null = New-Item $ph  -type directory}
  8.         Add-Type -AssemblyName "System.Drawing"
  9.         $ima = [System.Drawing.Imaging.Encoder]::Quality
  10.         $enc = New-Object System.Drawing.Imaging.EncoderParameters(1)
  11.         $enc.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter($ima, $lity)
  12.         $Code = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where {$_.MimeType -eq 'image/jpeg'}
  13.     }
  14.     process
  15.     {
  16.      $saveFile = Join-Path -Path $ph -ChildPath ($_.BaseName + '_' + $(Get-Date -Format "yyyyMMddHHmmssfff") + $_.Extension)
  17.      $img = [System.Drawing.Image]::FromFile($_)
  18.      $width = $img.Width
  19.      $height = $img.Height
  20.      if ($width -gt 3900 -or $height -gt 3900) {
  21.         if ($width -gt 5300 -or $height -gt 5300) {
  22.             $str =  $str +  "$_" +  "`n"
  23.         }else {$m = 4960 / [Math]::Max($width,$height)}
  24.      }else {$m = 3507 / [Math]::Max($width,$height)}
  25.      $w =[int] ($width * $m)
  26.      $h =[int] ($height * $m)
  27.      $size = New-Object System.Drawing.Bitmap($w, $h)
  28.      $tmp = [System.Drawing.Graphics]::FromImage($size)
  29.      $tmp.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
  30.      $tmp.Clear([System.Drawing.Color]::White)
  31.      $tmp.DrawImage($img, 0, 0, $w, $h)
  32.      $size.Save($saveFile, $Code, $($enc))
  33.      $img.Dispose()
  34.      $size.Dispose()
  35.      $tmp.Dispose()
  36.     }
  37.     end
  38.     {
  39.        $str
  40.        start "$ph"
  41.     }
  42. }
  43. $ph = $pwd.Path
  44. Get-ChildItem .\ *.jpg|?{!$_.PsIsContainer}| Imagefile -ph $ph -lity 60 -str "A2"
复制代码

TOP

回复 25# luckcsz
cmd 里也可以运行
还是保存为ps1文件 右键运行吧
至于不同后缀的图像文件应该可以处理 先试一下呢
对了 你什么系统

TOP

回复 29# luckcsz
可以放在图片目录运行
几种后缀可以把代码的44行开始换为下面的运行
当然 你也可以修改 ”$pwd.Path“ 这个是当前目录 你换为图片目录试呢
”$li = 60“ 这里的数值也可以修改
后面不加 -lity $li 参数的话 默认是90
运行前 请备份
  1. $ph = $pwd.Path
  2. $extlist = @('.tif','.jpg')
  3. $li = 60
  4. Get-ChildItem -path $ph |? { $extlist -eq $_.Extension }| ?{!$_.PsIsContainer} | Imagefile -ph $ph -lity $li -str "A2"
复制代码

TOP

回复 31# luckcsz
不清楚你那边运行环境 右键没有 使用PowersShell运行吗
假如你需处理图片文件在“d:\Image” 文件夹
在此文件夹 放入脚本并命名”Image.ps1“
再在此文件夹新建BAT文件 然后写入下面代码
运行看什么情况
  1. @echo off
  2. PowerShell -file  "d:\Image\Image.ps1"
  3. pause
复制代码

TOP

回复 43# luckcsz
ps1后缀 运行不了吗

TOP

返回列表