artech wrote: ↑2018-10-09T06:30:54-07:00I have another question. In above command how can I fill with gradient instead of solid color and again with preserving alpha?
You can use "-sparse-color" to add a gradient fill to the red, green, and blue channels of the input image while keeping the transparency of the alpha channel. A simple example command would look like this...
Code: Select all
magick icon.png -channel RGB -sparse-color barycentric "0,0 black %[w],0 white" icon3.png
You can specify any offsets you like in the "-sparse-color" operation by using
FX expressions. You can also use any colors. The command above starts the gradient with black at the upper left corner and ends with white at the upper right corner. To make the gradient go from red to green and from the upper left to the lower right, you could use something like this...
Code: Select all
magick icon.png -channel RGB -sparse-color barycentric "0,0 red %[w],%[h] green" icon4.png
This method would also work for making the image a single color by specifying the same color for the start and end of the "-sparse-color" operation, and it can take even more arguments to start several colors at various places in the image. See some instructions for "-sparse-color"
at THIS link.
Make sure to set the channels with "-channel RGB" before the coloring operation to make sure it's not modifying the alpha channel. And if necessary for more operations, you can re-activate the alpha channel with "+channel" right after coloring.
As always, in a BAT script you need to double the percent signs "%%".