anthony wrote:The barycentric method use to generate the gradient ensures that the gradient falling bteeen thw top-left to bottom-right diagonal, is at a 50% level between the top-right and bottom-left.
But if the image is square, then a baricentric with just two points will do the job (IM will calculate the third point)
-sparse-color barycentric '0,0 white %w,%h black'
Just a matter of coloring and setting transparency in that image.
As the overlay is square with transparency, just overlay it using 'Copy' Compostion.
That replaces just the overlay area with both color and transparency.
http://www.imagemagick.org/Usage/compose/#copy
This compose method is not often used, but in this case it is ideal.
Thanks Anthony. I knew there was compose method to do that, but could not think of it.
Here is the revised script according to Anthony's suggestions, which avoids the matte floodfill -draw:
infile="logo:"
pct=20
size=`convert $infile -format "%[fx:$pct*min(w,h)/100]" info:`
convert $infile \
\( -size ${size}x${size} xc: -sparse-color barycentric '0,0 red %w,%h black' +repage \) \
\( -size ${size}x${size} xc: -set colorspace RGB -sparse-color barycentric '0,0 white %w,%h black' \
-threshold 50% +repage \) \
\( -clone 1 -clone 2 -alpha off -compose copy_opacity -composite \) \
-delete 1,2 -gravity southeast -alpha set -compose copy -composite \
logo_redcorner.png