0

I'm trying to create a white background removal script and came across this:

Set transparent background using ImageMagick and commandline prompt

The solution from the above link that I want to implement is this:

color=$( convert filename.png -format "%[pixel:p{0,0}]" info:- )
convert filename.png -alpha off -bordercolor $color -border 1 \
    \( +clone -fuzz 30% -fill none -floodfill +0+0 $color \
       -alpha extract -geometry 200% -blur 0x0.5 \
       -morphology erode square:1 -geometry 50% \) \
    -compose CopyOpacity -composite -shave 1 outputfilename.png

The syntax is UNIX flavored. I want to utilize this call in Powershell. I'm hung up on this line:

color=$( convert filename.png -format "%[pixel:p{0,0}]" info:- )

$ is a variable prefix in PowerShell. Furthermore I don't even understand what that line is doing - it looks like it's storing a variable to be used in the next convert call.

Also, I don't know how to handle all the backslashes. Should I use a back-tick instead?

Can someone possibly refactor the above command to be compatible with PowerShell?

I appreciate any help at all.

fmotion1
  • 237
  • 4
  • 12
  • It sets the variable `color` to the result of running the command `convert ... info:-` You can run that `convert ... info:-` on its own and see what it produces - clue: it's the colour of the top-left pixel in the image. – Mark Setchell Mar 23 '23 at 10:47
  • The backslashes at the right end of the lines are *"line continuation"* characters. The backslashes preceding parentheses `(` and `)` are to escape their meaning in `bash` and are probably not required in Powershell. – Mark Setchell Mar 23 '23 at 10:50
  • You may need to double up the percent signs (`%`) if Powershell is anything like CMD32.EXE. – Mark Setchell Mar 23 '23 at 10:51

0 Answers0