Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
The last "-composite" will have the previous "-compose" setting, which is "SrcIn", which might not be what you want. But the previous bracket has a "-compose" with no "-composite", which is suspicious.
$cmd seems to write to stdout and read from stdin. This is fine, but it looks as if you want the stdin to be read from the stdout, which won't work in a single command.
rem Add a rounded corner by two different methods.
set SRC=logo:
set InRad=15
set OutRad=20
set BORDCOL=red
FOR /F "usebackq" %%L IN (`identify -format "WW=%%w\nHH=%%h" %SRC%`) DO set %%L
set /A wwOutRad=%WW%+OutRad
set /A hhOutRad=%HH%+OutRad
rem Method 1: three convert commands.
rem Create the red filled rounded rectangle
convert ^
-size %wwOutRad%x%hhOutRad% ^
xc:none ^
-fill %BORDCOL% -draw "roundRectangle 0,0 %wwOutRad%,%hhOutRad% %OutRad%,%OutRad%" ^
x.png
rem Create the image with the rounded rectangle
convert ^
-size %WW%x%HH% ^
xc:none ^
-fill white -draw "roundRectangle 0,0 %WW%,%HH% %InRad%,%InRad%" ^
%SRC% ^
-compose SrcIn -gravity center -composite ^
y.png
rem Combine the two
convert ^
x.png ^
y.png ^
-gravity center -compose Over -composite ^
border1.png
rem Method 2: Do it in one convert
convert ^
( ^
-size %wwOutRad%x%hhOutRad% ^
xc:none ^
-fill %BORDCOL% -draw "roundRectangle 0,0 %wwOutRad%,%hhOutRad% %OutRad%,%OutRad%" ^
) ^
( ^
-size %WW%x%HH% ^
xc:none ^
-fill white -draw "roundRectangle 0,0 %WW%,%HH% %InRad%,%InRad%" ^
%SRC% ^
-compose SrcIn -gravity center -composite ^
) ^
-gravity center -compose Over -composite ^
border2.png
convert
-size 646x340
xc:none -fill red -draw "roundRectangle 5,5 646,340 20,20"
-compose dstout -matte
( -size 636x330 xc:none -fill white -draw "roundRectangle 0,0 636,330 15,15"
small.jpg
-compose SrcIn -matte
)
-gravity center -compose over -composite
rounded_corners4.png
The first "-compose dstout -matte" is redundant. (It sets the compose method, but this setting is overwritten before it is used. "-matte" is implied by "xc:none".)
Likewise, -compose SrcIn -matte". But you need "-compose SrcIn -composite" here, to combine the rounded rectangle with small.jpg.
The only other difference to my version is the first roundRectangle. Your origin is "5,5" where mine is "0,0".