我正在嘗試將 bat 檔案轉換為 powershell 腳本。但是我無法解決 imagemagick 命令來確定照片是否為黑白色。
你能幫我嗎?w.
bat檔案:
for %%f in (*.jpg) do (
%%f
for /f %%i in ('magick "%%f" -colorspace HSL -channel g -separate channel -format "%%[fx:mean]" info:') do set VAR=%%i
if !VAR! LEQ 0.05 copy "%%f" .\bw)
電源外殼:
param ([string]$Path = "\\nas\photo\")
Add-Type -assembly "system.io.compression.filesystem"
$PathArray = @()
$magickExePath = "C:\Program Files\ImageMagick-7.1.0-Q16-HDRI\magick.exe"
Get-ChildItem $Path -directory -exclude "#recycle" -re |
ForEach-Object {
#$_.FullName
#$_.Name
If (($_.Name -match "landschap"))
{
$source = $_.FullName
$_.FullName
$_.name
$MagickArguments = "$_.name -colorspace HSL -channel g -separate channel -format "$_.name[fx:mean]" info:' "
$ColorLevel = $magickExePath $MagickArguments
}
}
我期待 $colorlevel 是一個介于 0 和 1 之間的數字。
uj5u.com熱心網友回復:
如果你想PowerShell來執行的可執行檔案,其路徑存盤在一個變數(或參考),您必須使用
&的電話運營商。要將引數存盤在變數中,請創建一個陣列,其中的每個元素代表一個要傳遞的單獨引數。
$MagickArguments = @(
$_.Name
'-colorspace'
'HSL'
'-channel'
'g'
'-separate'
' channel'
'-format'
'%[fx:mean]'
'info'
)
[double] $ColorLevel = & $magickExePath $MagickArguments
然而,直接傳遞引數會更簡單:
[double] $ColorLevel = & $magickExePath $_.Name -colorspace HSL -channel g -separate channel -format %[fx:mean] info:
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/393820.html
