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

Add-Type -AssemblyName System.Drawing
这个POWERSHELL直接就可以了吧

TOP

本帖最后由 terse 于 2024-4-22 01:56 编辑

修改一下 换回ForEach
  1. <# :
  2. @echo off
  3. powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
  4. pause
  5. exit
  6. #>
  7. Add-Type -AssemblyName System.Drawing
  8. function Remove-ICCProfile($images) {
  9.     $images.ForEach{
  10.         $temp = [IO.Path]::GetTempFileName()
  11.         $image = [Drawing.Image]::FromFile($_)
  12.         try {
  13.              $icc = $image.propertyItems.Id.Where{$_ -eq 0x8773}
  14.              if($icc){
  15.                 $image.RemovePropertyItem(0x8773)
  16.                 $image.Save($temp, [Drawing.Imaging.ImageFormat]::Jpeg)
  17.                 $image.Dispose()
  18.                 [IO.File]::Delete($_)
  19.                 [IO.File]::Move($temp, $_)
  20.              }
  21.         }
  22.         finally{ $image.Dispose() }
  23.     }
  24. }
  25. $images = [IO.Directory]::EnumerateFiles($pwd.Path, '*.jpg')
  26. Remove-ICCProfile $images
复制代码

TOP

回复 22# wh123wh123
bat没有你所需的处理图像方法,这个也是bat运行POWERSHELL代码,保存为BAT文件,运行请前先备份
  1. <# :
  2. @echo off
  3. powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
  4. pause
  5. exit
  6. #>
  7. Add-Type -AssemblyName System.Drawing
  8. function Remove-ICCProfile() {
  9.     param(
  10.         [string[]]$Images,
  11.         [int]$top,
  12.         [int]$bot
  13.     )
  14.     $images.foreach{
  15.         $temp = [IO.Path]::GetTempFileName()
  16.         try {
  17.             $image = [Drawing.Image]::FromFile($_)
  18.             $icc = $image.PropertyItems | Where-Object { $_.Id -eq 0x8773 }
  19.             if($icc){
  20.                 #$image.RemovePropertyItem(0x8773)
  21.                 $newWidth = $image.Width
  22.                 $newHeight = $image.Height - $top - $bot
  23.                 $target = New-Object Drawing.Bitmap($newWidth, $newHeight)
  24.                 $graphics = [Drawing.Graphics]::FromImage($target)
  25.                 $cropRect = [Drawing.Rectangle]::FromLTRB(0, 100, $image.Width, $image.Height - $bot)
  26.                 $graphics.DrawImage($image, 0, 0, $cropRect, [Drawing.GraphicsUnit]::Pixel)
  27.                 $graphics.Dispose()
  28.                 $target.Save($temp, [Drawing.Imaging.ImageFormat]::Jpeg)
  29.                 $target.Dispose()
  30.                 $image.Dispose()
  31.                 [IO.File]::Delete($_)
  32.                 [IO.File]::Move($temp, $_)
  33.             }
  34.         }
  35.         catch {
  36.             if ($image -ne $null) { $image.Dispose() }
  37.             if ($target -ne $null) { $target.Dispose() }
  38.         }
  39.     }
  40. }
  41. $images = [IO.Directory]::EnumerateFiles($pwd.Path, '*.jpg')
  42. Remove-ICCProfile $images -top 100 -bot 150
复制代码

TOP

回复 37# wh123wh123
win7不是带有powershell的吗

TOP

回复 54# wh123wh123
你系统带有POWERSHELL吗?不会是精简系统吧,在cmd你执行 powershell set-executionpolicy Unrestricted 试一下

TOP

返回列表