文件
fenleixinxi/tmp_img/detect_watermark.ps1
MiAn 133d425ec0 feat: 新增阿里云OSS适配器及分类图标优化
- 新增阿里云OSS SDK核心类库文件
- 新增OSS插件配置文件及钩子监听
- 新增分类图标SVG资源并优化为轻量化格式
- 替换定位接口为天地图逆地理编码接口
- 新增OSS图片缩略处理工具方法
2026-11-20 11:11:03 +08:00

69 行
2.7 KiB
PowerShell

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

# 批量检测图片右下角/右上角是否带角标文字
# 原理:角标区域通常有白底/灰底 + 高密度水平文字行
$ErrorActionPreference = 'Continue'
$dir = "D:\Softwares\phpstudy_pro\WWW\fenleixinxi\tmp_img\downloaded"
Add-Type -AssemblyName System.Drawing
function Detect-Watermark($filePath) {
try {
$img = [System.Drawing.Image]::FromFile($filePath)
$w = $img.Width
$h = $img.Height
$ratio = 0.18 # 底部 18% 区域
$rightRatio = 0.20 # 右侧 20%
# 右下区域
$regionRight = New-Object System.Drawing.RectangleF($w * (1 - $rightRatio), $h * (1 - $ratio), $w * $rightRatio, $h * $ratio)
$regionLeft = New-Object System.Drawing.RectangleF(0, $h * (1 - $ratio), $w * $rightRatio, $h * $ratio)
$bm = New-Object System.Drawing.Bitmap($img)
$img.Dispose()
function Scan-Region($bm, $rx, $ry, $rw, $rh, $name) {
$maxWhiteRows = 0
$whiteRowCount = 0
$rowStep = [Math]::Max(1, [int]($rh / 40))
for ($y = 0; $y -lt $rh; $y += $rowStep) {
$whiteInRow = 0
$totalChecked = 0
$colStep = [Math]::Max(1, [int]($rw / 40))
for ($x = 0; $x -lt $rw; $x += $colStep) {
$px = $bm.GetPixel([int]($rx + $x), [int]($ry + $y))
# 接近白色或浅灰(文字背景或反色字)
$lum = ($px.R * 0.299 + $px.G * 0.587 + $px.B * 0.114)
if ($lum -gt 210 -or ($lum -gt 180 -and $px.R -gt 170 -and $px.G -gt 170 -and $px.B -gt 170)) {
$whiteInRow++
}
$totalChecked++
}
$pct = $whiteInRow / [double]$totalChecked
if ($pct -gt 0.55) { $whiteRowCount++ }
}
return $whiteRowCount
}
$rRight = Scan-Region $bm ($w * (1 - $rightRatio)) ($h * (1 - $ratio)) ($w * $rightRatio) ($h * $ratio) "right"
$rLeft = Scan-Region $bm 0 ($h * (1 - $ratio)) ($w * $rightRatio) ($h * $ratio) "left"
$bm.Dispose()
return @{ right=$rRight; left=$rLeft }
} catch {
return $null
}
}
$files = Get-ChildItem $dir -Filter *.jpg
$suspicious = @()
foreach ($f in $files) {
$res = Detect-Watermark $f.FullName
if ($null -eq $res) { continue }
# 阈值:白底行数 > 6 行基本就是角标块(40 采样行里)
if ($res.right -gt 6 -or $res.left -gt 6) {
$suspicious += @{ name=$f.Name; right=$res.right; left=$res.left }
}
}
Write-Output "TOTAL=$($files.Count)"
Write-Output "SUSPICIOUS=$($suspicious.Count)"
$suspicious | Sort-Object right -Descending | Select-Object -First 20 | Format-Table -AutoSize