Page 1 of 1

using draw with alpha

Posted: 2017-05-30T07:34:53-07:00
by jox81
Hello,

I'm trying to find a "singleline" command to draw a rectangle in the alpha channel.

This work in the rgb channel :

Code: Select all

-alpha opaque -fill 'rgba( 0, 0, 0 , 0.5 )' -draw 'rectangle 66,50 200,150' 
This work in the alpha channel :

Code: Select all

-alpha opaque -fill 'rgba( 0, 0, 0 , 0.5 )' -draw 'alpha 4,4 point' 
I don't know if this is possible, but how can i draw a rectangle directly in the alpha channel ?

Thanks in advance
:D

Re: using draw with alpha

Posted: 2017-05-30T07:36:59-07:00
by snibgo
What version IM do you use? On what platform?

Re: using draw with alpha

Posted: 2017-05-30T23:25:56-07:00
by jox81
Sorry for the lack of informations.

I'm on windows 10 with ImageMagick-7.0.5-9-Q16-x64.

Re: using draw with alpha

Posted: 2017-05-31T09:06:41-07:00
by fmw42
Using the IM internal image logo:. You can replace that with your image of the form image.suffix

Windows syntax:

Code: Select all

magick logo: -alpha set ^
( +clone -alpha extract -fill black -draw "translate 320,240 rectangle -100,-100 100,100" ) ^
-alpha off -compose copy_opacity -composite result.png
If using Windows 10 unix, then

Code: Select all

magick logo: -alpha set \
\( +clone -alpha extract -fill black -draw "translate 320,240 rectangle -100,-100 100,100" \) \
-alpha off -compose copy_opacity -composite result.png

Re: using draw with alpha

Posted: 2017-05-31T10:04:53-07:00
by snibgo
To draw with transparent fill, the image you are drawing on should be fully transparent. For example (Windows BAT syntax):

Code: Select all

%IMG7%magick ^
  -size 600x400 xc: -alpha transparent ^
  -fill rgba(75%%,100%%,0,0.35) ^
  -draw "rectangle 66,50 200,150" ^
  -draw "rectangle 150,100 250,300" ^
  out.png
If you want to draw with transparent fill over an opaque image: first clone the image, make it transparent, draw on it, and composite this over the opaque image.

Code: Select all

%IMG7%magick ^
  logo: ^
  ( +clone -alpha transparent ^
    -fill rgba(75%%,100%%,0,0.35) ^
    -draw "rectangle 66,50 200,150" ^
    -draw "rectangle 150,100 250,300" ^
  ) ^
  -compose Over -composite ^
  transdraw.png
Image

Does that answer the question?

EDIT: An alternative is to use "-background None":

Code: Select all

%IMG7%magick ^
  logo: ^
  -background none ^
  -fill rgba(75%%,100%%,0,0.35) ^
  -draw "rectangle 66,50 200,150" ^
  -draw "rectangle 150,100 250,300" ^
  transdraw2.png