- 新增阿里云OSS SDK核心类库文件 - 新增OSS插件配置文件及钩子监听 - 新增分类图标SVG资源并优化为轻量化格式 - 替换定位接口为天地图逆地理编码接口 - 新增OSS图片缩略处理工具方法
69 行
2.7 KiB
PowerShell
69 行
2.7 KiB
PowerShell
# 批量检测图片右下角/右上角是否带角标文字
|
||
# 原理:角标区域通常有白底/灰底 + 高密度水平文字行
|
||
$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
|