0

This code:

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"

running with errors... Main problem with Parentheses
Can't understand how to use them correctly

Mis Urb
  • 11
  • 2
  • Have a look here https://stackoverflow.com/a/64243920/2836621 – Mark Setchell Oct 07 '20 at 19:57
  • Yes, but i use this rules... and don't work – Mis Urb Oct 07 '20 at 20:02
  • Have you got any spaces after the carets (`^`) at the ends of the lines? – Mark Setchell Oct 07 '20 at 20:03
  • What'e the error message? – Mark Setchell Oct 07 '20 at 20:04
  • Did you double up the percent signs? – Mark Setchell Oct 07 '20 at 20:04
  • 1
    Is it in DOS Windows CMD window or in a .bat file or using Powershell or something like that. Each has specific syntax rules. What were your error messages? – fmw42 Oct 07 '20 at 22:09
  • This is not a PowerShell code issue. You are literally running a 3rdP external executable. Running executables must be properly called. This is a well-documented use case, meaning, using PowerShell to run executables. [PowerShell Running Executables](https://social.technet.microsoft.com/wiki/contents/articles/7703.powershell-running-executables.aspx). Everything about the posted code is syntactically wrong from a PowerShell perspective. This [ ^], is not a code line continuation character in PowerShell. This [(...)] is not that way you pass parameters/arguments in PowerShell. – postanote Oct 08 '20 at 04:01

1 Answers1

0

Full disclosure: I've never used ImageMagick. However, as previously stated in my comment, executables must be called correctly ...

PowerShell Running Executables

A quick search using...

'PowerShell ImageMagick'

... provides this sample of how to run the external executable via Powershell, as detailed in the MS link above. Based on what you posted, you won't need all of it. Just the convert section. Yet, it still must be all on one line.

PowerShell ImageMagick

# 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"); 
      }
}

So, your command as per the MS link and the sample posted would be something link this...

& 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"

Yet, again, I don't use this product, so this convert.exe specific syntax still may be problematic (since I cannot test this for validation) as if reflects that way in the ISE/VSCode.

postanote
  • 15,138
  • 2
  • 14
  • 25