返回列表 发帖
回复 15# 77七
图片里的最上面的无用内容和最下面的二维码用批处理能不能删除掉?

TOP

回复 8# buyiyang


    图片里的最上面的无用内容和最下面的二维码用批处理能不能删除掉?

TOP

回复 17# wh123wh123


    whiteCoverJPG.ps1
Add-Type -AssemblyName System.Drawing
function Cover-Image {
    param(
        [string]$ImagePath,
        [int]$TopCover,
        [int]$BottomCover
    )
    $originalImage = [System.Drawing.Image]::FromFile($ImagePath)
    $originalHeight = $originalImage.Height
    $originalWidth = $originalImage.Width
    $graphics = [System.Drawing.Graphics]::FromImage($originalImage)
    $whiteBrush = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::White)
    $graphics.FillRectangle($whiteBrush, 0, 0, $originalWidth, $TopCover)
    $graphics.FillRectangle($whiteBrush, 0, $originalHeight - $BottomCover, $originalWidth, $BottomCover)
    $coveredImagePath = [System.IO.Path]::ChangeExtension($ImagePath, "covered.jpg")
    $originalImage.Save($coveredImagePath, [System.Drawing.Imaging.ImageFormat]::Jpeg)
}
# 白色覆盖顶部100像素,底部150像素
$topCover = 100
$bottomCover = 150
dir *.jpg | ForEach-Object {
    Cover-Image -ImagePath $_.FullName -TopCover $topCover -BottomCover $bottomCover
    }COPY

TOP

回复  wh123wh123


    whiteCoverJPG.ps1
buyiyang 发表于 2024-4-21 23:10



这个代码怎么使用?

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

我帮忙写的代码不需要付钱。如果一定要给,请在微信群或QQ群发给大家吧。
【微信公众号、微信群、QQ群】http://bbs.bathome.net/thread-3473-1-1.html
【支持批处理之家,加入VIP会员!】http://bbs.bathome.net/thread-67716-1-1.html

TOP

回复 20# terse



    PowerShell 代码使用不太方便,能不能用BAT解决?包括删除图片右下角的二维码和页眉上方的无用内容?

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

回复 23# terse



    POWERSHELL是什么?也是一个exe程序?需要下载放到同一个文件夹?还是?

TOP

回复 21# Batcher

安装POWERSHELL电脑会变慢,有没有其他处理办法?比如VBS

TOP

回复 24# wh123wh123


    win10 win11 自带 powershell.exe

QQ 20147578

TOP

回复 26# czjt1234

WIN7,另外问问,用BAT能不能以图片处理的方法,
    用BAT如何把图片里指定位置的不需要的图案区域填充变成白色?下面是我手动去除下面的二维码和最上面无用的广告,bat能不能代替手工自动处理?
选中图片-右键编辑-点选中【颜色1】-点击【颜色选取器】为白色使【颜色1】变为白色-点击【矩形】-点击【“填充”为“纯色”】-鼠标移动到需要变白的区域即可变成白色,最后保存即可。

TOP

回复 15# 77七

用BAT能不能以图片处理的方法,
    用BAT如何把图片里指定位置的不需要的图案区域填充变成白色?下面是我手动去除下面的二维码和最上面无用的广告,bat能不能代替手工自动处理?
选中图片-右键编辑-点选中【颜色1】-点击【颜色选取器】为白色使【颜色1】变为白色-点击【矩形】-点击【“填充”为“纯色”】-鼠标移动到需要变白的区域即可变成白色,最后保存即可。

TOP

回复 28# wh123wh123


   bat只有调用ffmpeg等工具才好处理,命令还需要网上找,我试着找了几个,存在一些问题。
bat小白,请多指教!谢谢!

TOP

回复 28# wh123wh123


  
@echo off
rem 下载 "https://imagemagick.org/archive/binaries/ImageMagick-7.1.1-31-portable-Q8-x64.zip"
cd /d "%~dp0"
set "_exiftool=D:\exiftool-12.83\exiftool(-k).exe"
set "_magick=D:\magick.exe"
"%_exiftool%" -icc_profile= *.jpg
del "*jpg_original"
rem 0,0,1200,100 xyxy 左上角及右下角坐标
for %%a in (*.jpg) do (
"%_magick%" "%%a" -fill white -draw "rectangle 0,0,1200,100 rectangle 0,1660,1280,1800" "copy_%%a"
move "copy_%%a" "%%a"
)
pauseCOPY
ai找了个代码,我自己胡乱修改,同时去除两个区域,需要使用magick,使用前先备份,不合适自行调整下坐标。
1

评分人数

    • wh123wh123: 感谢老师的帮助,中间的那一行大红色字体能 ...技术 + 1
bat小白,请多指教!谢谢!

TOP

返回列表