How to draw with tranparent color / how draw erasures?

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
waldalla
Posts: 10
Joined: 2011-10-02T11:12:42-07:00
Authentication code: 8675308

How to draw with tranparent color / how draw erasures?

Post by waldalla »

I want create a blue doughnut on transparent background. So far I have a circle on trans[arenty background with a white middle:

Code: Select all

convert -size 1001x1001 xc:white -alpha transparent transparent.png
convert transparent.png -fill "#2244aa" -stroke "#2244aa" -draw "circle 500,500 1,500" circle.png
convert circle.png -fill "white" -stroke "white" -draw "circle 500,500 400,500" circle.png
convert circle.png -resize 19x19 circle.png
How can I make the middle transparent instead of white? I tried -alpha transparent, but this gives me a completely white result:

Code: Select all

convert circle.png -draw "circle 500,500 400,500"  -alpha transparent circle.png
I'm looking for some way to "draw" with transparency as the color.

Thanks for all pointers in advance!
---
Walter Dallaway
* Landscape and Architecture Photography
* Creativ Exposure with Tripod and HDR
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to draw with tranparent color / how draw erasures?

Post by snibgo »

I would draw a grayscale image, then copy-opacity that to form the alpha channel:

Code: Select all

convert -size 1001x1001 xc:#2244aa ^
  ( +clone -fill Black -colorize 100 ^
    -fill White -draw "circle 500,500,1,500" ^
    -fill Black -draw "circle 500,500,400,500" ^
  ) ^
  -alpha off ^
  -compose CopyOpacity -composite ^
  out.png
(Windows BAT syntax. Adjust for bash.)
snibgo's IM pages: im.snibgo.com
waldalla
Posts: 10
Joined: 2011-10-02T11:12:42-07:00
Authentication code: 8675308

Re: How to draw with tranparent color / how draw erasures?

Post by waldalla »

Thanks snibgo. Will try it out.

From the script I understand that you create the doughnut in b/w and then use the black parts as a "stamp" to put on a empty (=transparent) background. Very clever!
---
Walter Dallaway
* Landscape and Architecture Photography
* Creativ Exposure with Tripod and HDR
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: How to draw with tranparent color / how draw erasures?

Post by anthony »

A Number of ways... Here are two...

Using Masks with Images
http://www.imagemagick.org/Usage/masking/#masks

Composing using Duff-Porter methods, Specifically with Dst-Out
http://www.imagemagick.org/Usage/compose/#dstout

But essentially you want to manipulate the images alpha channel, either directly as in the first, or using alpha composition, as in the second.

Anthony
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply