问题描述
此代码:
convert "D:\3.jpg" ^
( -size 1000x600 -background white -fill black -gravity center -font IM-FELL-English-Roman label:"TERRAZO\nPATTERN" ^
-bordercolor white -border 20 -bordercolor black -border 20 -bordercolor white -border 50 ) ^
( +clone -fill "gray(15%)" -colorize 100 -virtual-pixel white -blur 0x40 -level 0x50% ) ^
( -clone 1 -shave 40x40 -clone 2 +swap -gravity center -compose over -composite ) ^
-delete 1,2 ^
-gravity center -compose over -composite "D:\result.jpg"
正在运行错误...
括号的主要问题
无法理解如何正确使用它们
解决方法
完整披露: 我从未使用过ImageMagick。但是,正如我之前在评论中所述,必须正确调用可执行文件...
使用...进行快速搜索
...提供了有关如何通过Powershell运行外部可执行文件的示例,如上面的MS链接中所述。根据您发布的内容,您将不需要全部。只是转换部分。但是,它仍然必须全部放在一行上。
isdigit(ch)
因此,根据MS链接和所发布示例的命令将是与此相关的链接...
# Windows Powershell Wrapper Script for ImageMagick
cls
$inputPath = "e:\Photos\ToResize\"
$targetPath = "e:\Photos\Resized\"
$files = get-ChildItem $inputPath
foreach ($file in $files)
{
#$output = & magick identify e:\Photos\ToResize2cca60-a2a9-49b8-964e-b228acf517f3.jpg
# shell out to run the ImageMagick "identify" command
$output = & magick identify $file.FullName
$outFilename = $targetPath + $file.Name
# sample value of $output:
#e:\Photos\ToResize2cca60-a2a9-49b8-964e-b228acf517f3.jpg JPEG 768x512 768x512+0+0 8-bit sRGB 111420B 0.000u 0:00.000
write-host $output
$pattern = ".* (\d*?)x(\d*?) .*"
#the first parenthese is for capturing the cityState into the $Matches array
#the second parentheses are needed above to look for $ (which is end of line)
#or zip code following the city/state
$isMatch = $output -match $pattern
if ($Matches.Count -gt 0)
{
#$width = $Matches[1];
#$height = $Matches[2];
[int]$width = [convert]::ToInt32($Matches[1]);
[int]$height = [convert]::ToInt32($Matches[2]);
if ($height -gt $width)
{
$orientation = "tall";
# shell out to run the ImageMagick "convert" command
& convert -define jpeg:size=510x510 $file.FullName -thumbnail "510x510>" -background white -gravity center -extent "510x510" $outFilename
}
else
{
$orientation = "wide";
# shell out to run the ImageMagick "convert" command
& convert -resize 510x510^ $file.FullName $outFilename
}
Write-Host ("file=$($file.name) width=$width height=$height orientation=$orientation `n`n");
}
else
{
Write-Host ("No matches");
}
}
再次,我没有使用此产品,因此,特定于convert.exe的语法仍然可能有问题(因为我无法对此进行测试以进行验证),就像在ISE / VSCode中反映了这种方式一样。