using draw with alpha

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?".
Post Reply
jox81
Posts: 2
Joined: 2017-05-30T07:22:34-07:00
Authentication code: 1151

using draw with alpha

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: using draw with alpha

Post by snibgo »

What version IM do you use? On what platform?
snibgo's IM pages: im.snibgo.com
jox81
Posts: 2
Joined: 2017-05-30T07:22:34-07:00
Authentication code: 1151

Re: using draw with alpha

Post by jox81 »

Sorry for the lack of informations.

I'm on windows 10 with ImageMagick-7.0.5-9-Q16-x64.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: using draw with alpha

Post 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
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: using draw with alpha

Post 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
snibgo's IM pages: im.snibgo.com
Post Reply