When testing EXE files in PowerShell, EchoArgs.exe is a very useful tool to have on hand. The original source for this tool appears to have disappeared, but you can still download it from ss64.com on this page.
When dealing with complex command lines for EXE files, Stop-parsing token (--%) is a very useful special parsing token to keep in mind.
In the command line execute EchoArgs with your parameters:
EchoArgs nature.jpg -set option:watermarkWidth "%[fx:int(w*0.25)]" -alpha set -background none ( -fill "#FFFFFF80" -stroke "#FF000080" -strokeWidth 3 -undercolor "#FF000080" -size "%[watermarkWidth]x" label:"THIS IS WATERMARK" -gravity center -geometry +10+10 -rotate -30 ) -composite -quality 40 nature_wm.jpg
Record your results:
Arg 0 is <nature.jpg>
Arg 1 is <-set>
Arg 2 is <option:watermarkWidth>
Arg 3 is <%[fx:int(w*0.25)]>
Arg 4 is <-alpha>
Arg 5 is <set>
Arg 6 is <-background>
Arg 7 is <none>
Arg 8 is <(>
Arg 9 is <-fill>
Arg 10 is <#FFFFFF80>
Arg 11 is <-stroke>
Arg 12 is <#FF000080>
Arg 13 is <-strokeWidth>
Arg 14 is <3>
Arg 15 is <-undercolor>
Arg 16 is <#FF000080>
Arg 17 is <-size>
Arg 18 is <%[watermarkWidth]x>
Arg 19 is <label:THIS IS WATERMARK>
Arg 20 is <-gravity>
Arg 21 is <center>
Arg 22 is <-geometry>
Arg 23 is <+10+10>
Arg 24 is <-rotate>
Arg 25 is <-30>
Arg 26 is <)>
Arg 27 is <-composite>
Arg 28 is <-quality>
Arg 29 is <40>
Arg 30 is <nature_wm.jpg>
To avoid problem, use --% in PowerShell at the point where the command line becomes complex:
EchoArgs nature.jpg -set option:watermarkWidth --% "%[fx:int(w*0.25)]" -alpha set -background none ( -fill "#FFFFFF80" -stroke "#FF000080" -strokeWidth 3 -undercolor "#FF000080" -size "%[watermarkWidth]x" label:"THIS IS WATERMARK" -gravity center -geometry +10+10 -rotate -30 ) -composite -quality 40 nature_wm.jpg
Check your results:
Arg 0 is <nature.jpg>
Arg 1 is <-set>
Arg 2 is <option:watermarkWidth>
Arg 3 is <%[fx:int(w*0.25)]>
Arg 4 is <-alpha>
Arg 5 is <set>
Arg 6 is <-background>
Arg 7 is <none>
Arg 8 is <(>
Arg 9 is <-fill>
Arg 10 is <#FFFFFF80>
Arg 11 is <-stroke>
Arg 12 is <#FF000080>
Arg 13 is <-strokeWidth>
Arg 14 is <3>
Arg 15 is <-undercolor>
Arg 16 is <#FF000080>
Arg 17 is <-size>
Arg 18 is <%[watermarkWidth]x>
Arg 19 is <label:THIS IS WATERMARK>
Arg 20 is <-gravity>
Arg 21 is <center>
Arg 22 is <-geometry>
Arg 23 is <+10+10>
Arg 24 is <-rotate>
Arg 25 is <-30>
Arg 26 is <)>
Arg 27 is <-composite>
Arg 28 is <-quality>
Arg 29 is <40>
Arg 30 is <nature_wm.jpg>
But what if you need to dynamically replace part of the parameters after the the Stop-parsing token (--%)? That is doable via environmental variables:
$Env:FirstValue = '%[fx:int(w*0.25)]'
$Env:Alpha = 'set'
$Env:Background = 'none'
$Env:Fill = '#FFFFFF80'
$Env:Stroke = '#FF000080'
$Env:StrokeWidth = '3'
$Env:Undercolor = '#FF000080'
$Env:Size = '%[watermarkWidth]x'
$Env:Label = 'THIS IS WATERMARK'
$Env:Gravity = 'center'
$Env:Geometry = '+10+10'
$Env:Rotate = '-30'
$Env:Quality = '40'
$Env:ImgName = 'nature_wm.jpg'
EchoArgs nature.jpg -set option:watermarkWidth --% "%FirstValue%" -alpha %Alpha% -background %Background% ( -fill "%Fill%" -stroke "%Stroke%" -strokeWidth %StrokeWidth% -undercolor "%Undercolor%" -size "%[watermarkWidth]x" label:"%Label%" -gravity %Gravity% -geometry %Geometry% -rotate %Rotate% ) -composite -quality %Quality% %ImgName%
Again, check your results:
Arg 0 is <nature.jpg>
Arg 1 is <-set>
Arg 2 is <option:watermarkWidth>
Arg 3 is <%[fx:int(w*0.25)]>
Arg 4 is <-alpha>
Arg 5 is <set>
Arg 6 is <-background>
Arg 7 is <none>
Arg 8 is <(>
Arg 9 is <-fill>
Arg 10 is <#FFFFFF80>
Arg 11 is <-stroke>
Arg 12 is <#FF000080>
Arg 13 is <-strokeWidth>
Arg 14 is <3>
Arg 15 is <-undercolor>
Arg 16 is <#FF000080>
Arg 17 is <-size>
Arg 18 is <%[watermarkWidth]x>
Arg 19 is <label:THIS IS WATERMARK>
Arg 20 is <-gravity>
Arg 21 is <center>
Arg 22 is <-geometry>
Arg 23 is <+10+10>
Arg 24 is <-rotate>
Arg 25 is <-30>
Arg 26 is <)>
Arg 27 is <-composite>
Arg 28 is <-quality>
Arg 29 is <40>
Arg 30 is <nature_wm.jpg>
But what if you don't know where the EXE is and have to search for it on the hard drive and call it from a variable? Use The call operator (&):
$Program = 'C:\Program Files\ImageMagick-7.0.11-Q16-HDRI\magick.exe'
$Env:FirstValue = '%[fx:int(w*0.25)]'
$Env:Alpha = 'set'
$Env:Background = 'none'
$Env:Fill = '#FFFFFF80'
$Env:Stroke = '#FF000080'
$Env:StrokeWidth = '3'
$Env:Undercolor = '#FF000080'
$Env:Size = '%[watermarkWidth]x'
$Env:Label = 'THIS IS WATERMARK'
$Env:Gravity = 'center'
$Env:Geometry = '+10+10'
$Env:Rotate = '-30'
$Env:Quality = '40'
$Env:ImgName = 'nature_wm.jpg'
& $Program nature.jpg -set option:watermarkWidth --% "%FirstValue%" -alpha %Alpha% -background %Background% ( -fill "%Fill%" -stroke "%Stroke%" -strokeWidth %StrokeWidth% -undercolor "%Undercolor%" -size "%[watermarkWidth]x" label:"%Label%" -gravity %Gravity% -geometry %Geometry% -rotate %Rotate% ) -composite -quality %Quality% %ImgName%
Now, having said all that, the real test is to actually execute the command and see if it works. I don't have your image file and not really up to doing any experiments with Image Magick. But, in theory, this command should work work for you:
magick nature.jpg -set option:watermarkWidth --% "%[fx:int(w*0.25)]" -alpha set -background none ( -fill "#FFFFFF80" -stroke "#FF000080" -strokeWidth 3 -undercolor "#FF000080" -size "%[watermarkWidth]x" label:"THIS IS WATERMARK" -gravity center -geometry +10+10 -rotate -30 ) -composite -quality 40 nature_wm.jpg
EDIT:
If you ware wanting MagicK to run in GoLang, use the following code:
package main
import (
"fmt"
"os/exec"
)
func main() {
data, err := exec.Command("magick", "nature.jpg", "-set", "option:watermarkWidth", "%[fx:int(w*0.25)]", "-alpha", "set", "-background", "none", "(", "-fill", "#FFFFFF80", "-stroke", "#FF000080", "-strokeWidth", "3", "-undercolor", "#FF000080", "-size", "%[watermarkWidth]x", "label:THIS IS WATERMARK", "-gravity", "center", "-geometry", "+10+10", "-rotate", "-30", ")", "-composite", "-quality", "40", "nature_wm.jpg").Output()
if err != nil {
panic(err)
}
fmt.Println(string(data))
}