[英]howto use imagemagick in powershell
I'm trying to convert a bat file into a powershell script.我正在尝试将 bat 文件转换为 powershell 脚本。 But I cannot solve the imagemagick command to determine if the photo is blackwhite.
但我无法解决 imagemagick 命令来确定照片是否为黑白。
Can you assist me?你能帮帮我吗? w.
w。
batfile:蝙蝠文件:
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)
powershell: powershell:
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
}
}
If you want PowerShell to execute an executable whose path is stored in a variable (or is quoted ), you must use &
, the call operator .如果您希望 PowerShell 执行其路径存储在变量中(或被引用)的可执行文件,则必须使用
&
, 调用运算符。
To store arguments in a variable, create an array , each element of which represents a separate argument to pass.要将 arguments 存储在变量中,请创建一个数组,其中每个元素代表一个要传递的单独参数。
$MagickArguments = @(
$_.Name
'-colorspace'
'HSL'
'-channel'
'g'
'-separate'
'+channel'
'-format'
"$($_.Name)[fx:mean]"
'info'
)
$ColorLevel = & $magickExePath $MagickArguments
It would be simpler to pass the arguments directly however:但是,直接通过 arguments 会更简单:
$ColorLevel = & $magickExePath $_.Name -colorspace HSL -channel g -separate +channel -format "$($_.Name)[fx:mean]" info:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.