[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 15# 77七
图片里的最上面的无用内容和最下面的二维码用批处理能不能删除掉?

TOP

回复 8# buyiyang


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

TOP

回复 17# wh123wh123


    whiteCoverJPG.ps1
  1. Add-Type -AssemblyName System.Drawing
  2. function Cover-Image {
  3.     param(
  4.         [string]$ImagePath,
  5.         [int]$TopCover,
  6.         [int]$BottomCover
  7.     )
  8.     $originalImage = [System.Drawing.Image]::FromFile($ImagePath)
  9.     $originalHeight = $originalImage.Height
  10.     $originalWidth = $originalImage.Width
  11.     $graphics = [System.Drawing.Graphics]::FromImage($originalImage)
  12.     $whiteBrush = New-Object System.Drawing.SolidBrush([System.Drawing.Color]::White)
  13.     $graphics.FillRectangle($whiteBrush, 0, 0, $originalWidth, $TopCover)
  14.     $graphics.FillRectangle($whiteBrush, 0, $originalHeight - $BottomCover, $originalWidth, $BottomCover)
  15.     $coveredImagePath = [System.IO.Path]::ChangeExtension($ImagePath, "covered.jpg")
  16.     $originalImage.Save($coveredImagePath, [System.Drawing.Imaging.ImageFormat]::Jpeg)
  17. }
  18. # 白色覆盖顶部100像素,底部150像素
  19. $topCover = 100
  20. $bottomCover = 150
  21. dir *.jpg | ForEach-Object {
  22.     Cover-Image -ImagePath $_.FullName -TopCover $topCover -BottomCover $bottomCover
  23.     }
复制代码

TOP

回复  wh123wh123


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



这个代码怎么使用?

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

我帮忙写的代码不需要付钱。如果一定要给,请在微信群或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文件,运行请前先备份
  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

回复 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


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

评分人数

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

TOP

返回列表