Files
EJM_Display/Pictures/批量修改为sRGB图片.ps1

41 lines
1.4 KiB
PowerShell
Raw Normal View History

2025-10-16 17:40:00 +08:00
# 配置图片根目录(已填写你的路径)
$rootDirectory = ".\"
# 要处理的图片格式仅处理PNG可根据需要添加其他格式
$imageExtensions = @("*.png")
# ImageMagick的magick命令路径默认安装路径需根据实际安装情况修改
$magickPath = "D:\Application\ImageMagick-7.1.2-Q16-HDRI\magick.exe"
# 检查magick.exe是否存在
if (-not (Test-Path $magickPath)) {
Write-Host "错误未找到magick.exe请检查ImageMagick安装路径是否正确" -ForegroundColor Red
Write-Host "提示默认路径为C:\Program Files\ImageMagick-版本号\magick.exe" -ForegroundColor Yellow
exit
}
# 递归查找所有图片文件
$imageFiles = Get-ChildItem -Path $rootDirectory -Include $imageExtensions -Recurse -File
if ($imageFiles.Count -eq 0) {
Write-Host "未找到任何图片文件" -ForegroundColor Yellow
exit
}
# 批量处理图片
foreach ($file in $imageFiles) {
Write-Host "正在处理: $($file.FullName)"
# 使用magick命令路径添加引号处理特殊字符
& $magickPath "$($file.FullName)" -strip "$($file.FullName)"
# 检查处理结果
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ 处理成功: $($file.Name)" -ForegroundColor Green
} else {
Write-Host "❌ 处理失败: $($file.Name)" -ForegroundColor Red
}
}
Write-Host "`n处理完成,共处理了 $($imageFiles.Count) 个文件" -ForegroundColor Cyan