微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Windows 7上ImageMagick中的括号用法

如何解决Windows 7上ImageMagick中的括号用法

代码

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 Running Executables

使用...进行快速搜索

'PowerShell ImageMagick'

...提供了有关如何通过Powershell运行外部可执行文件的示例,如上面的MS链接中所述。根据您发布的内容,您将不需要全部。只是转换部分。但是,它仍然必须全部放在一行上。

PowerShell ImageMagick

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中反映了这种方式一样。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。