返回列表 发帖
回复 8# buyiyang

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

TOP

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

修改一下 换回ForEach
<# :
@echo off
powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
pause
exit
#>
Add-Type -AssemblyName System.Drawing
function Remove-ICCProfile($images) {
    $images.ForEach{
        $temp = [IO.Path]::GetTempFileName()
        $image = [Drawing.Image]::FromFile($_)
        try {
             $icc = $image.propertyItems.Id.Where{$_ -eq 0x8773}
             if($icc){
                $image.RemovePropertyItem(0x8773)
                $image.Save($temp, [Drawing.Imaging.ImageFormat]::Jpeg)
                $image.Dispose()
                [IO.File]::Delete($_)
                [IO.File]::Move($temp, $_)
             }
        }
        finally{ $image.Dispose() }
    }
}
$images = [IO.Directory]::EnumerateFiles($pwd.Path, '*.jpg')
Remove-ICCProfile $imagesCOPY

TOP

回复 22# wh123wh123
bat没有你所需的处理图像方法,这个也是bat运行POWERSHELL代码,保存为BAT文件,运行请前先备份
<# :
@echo off
powershell -noprofile -NoLogo "iex (${%~f0} | out-string)"
pause
exit
#>
Add-Type -AssemblyName System.Drawing
function Remove-ICCProfile() {
    param(
        [string[]]$Images,
        [int]$top,
        [int]$bot
    )
    $images.foreach{
        $temp = [IO.Path]::GetTempFileName()
        try {
            $image = [Drawing.Image]::FromFile($_)
            $icc = $image.PropertyItems | Where-Object { $_.Id -eq 0x8773 }
            if($icc){
                #$image.RemovePropertyItem(0x8773)
                $newWidth = $image.Width
                $newHeight = $image.Height - $top - $bot
                $target = New-Object Drawing.Bitmap($newWidth, $newHeight)
                $graphics = [Drawing.Graphics]::FromImage($target)
                $cropRect = [Drawing.Rectangle]::FromLTRB(0, 100, $image.Width, $image.Height - $bot)
                $graphics.DrawImage($image, 0, 0, $cropRect, [Drawing.GraphicsUnit]::Pixel)
                $graphics.Dispose()
                $target.Save($temp, [Drawing.Imaging.ImageFormat]::Jpeg)
                $target.Dispose()
                $image.Dispose()
                [IO.File]::Delete($_)
                [IO.File]::Move($temp, $_)
            }
        }
        catch {
            if ($image -ne $null) { $image.Dispose() }
            if ($target -ne $null) { $target.Dispose() }
        }
    }
}
$images = [IO.Directory]::EnumerateFiles($pwd.Path, '*.jpg')
Remove-ICCProfile $images -top 100 -bot 150COPY

TOP

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

TOP

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

TOP

返回列表