Circular Colour Gradient limited to a Circular Area

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
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Circular Colour Gradient limited to a Circular Area

Post by whugemann »

I haven't worked with transpareny a lot so far, so this question might have a simple answer. I would like to create a circular gragient from, say, yellow to red as described in http://www.imagemagick.org/Usage/canvas ... l-gradient. I would like to place the resulting image over the centre of another, larger image (to simulate the laser aiming device of a speed trap).

The overlay should however consist of a circular area rather than a circle surrounded by a square. So far, I get along with creating a circular gradient with transparency and overlaying this to the final image. But this is not quite what I am trying to achive.
Wolfgang Hugemann
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Circular Colour Gradient limited to a Circular Area

Post by fmw42 »

Wolfgang,

Not exactly sure what you want. Can you post a link to what you have and explain how you want it different?

Have you tried using -distort arc starting with a linear gradient? see http://www.imagemagick.org/Usage/distorts/#arc
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Circular Colour Gradient limited to a Circular Area

Post by Bonzo »

As I read it whugemann wants a circular gradiant that ends in a circle without extending to the corners of the image - like an iris. Outside the iris would be transparent to the corners.

I suppose you could create a normal circular gradiant and use a mask with a round hole?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Circular Colour Gradient limited to a Circular Area

Post by fmw42 »

Bonzo wrote:As I read it whugemann wants a circular gradiant that ends in a circle without extending to the corners of the image - like an iris. Outside the iris would be transparent to the corners.

I suppose you could create a normal circular gradiant and use a mask with a round hole?

I may be mistaken. You may be right. If one wants a radial gradient then do it your way. If you want an angular gradient, then -distort arc would be the way. I probably misunderstood about the radial aspect.

Alternately, try -distort polar with a linear gradient
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Circular Colour Gradient limited to a Circular Area

Post by fmw42 »

Is this what you are trying to do:

convert -size 100x100 radial-gradient:yellow-red -transparent red radial_grad_yellow_red.png

Image

If not, can you explain what needs changing?


Or this:

convert -size 100x100 radial-gradient: -negate -black-threshold 30% -level 30%x100% +level-colors yellow,red -transparent yellow -transparent red radial_grad_yellow_red2.png

Image



Or this:

convert -size 100x50 gradient:red-yellow -virtual-pixel HorizontalTile -background none -distort arc "360 0 100 25" grad_red_yellow_arc.png


Image
User avatar
whugemann
Posts: 289
Joined: 2011-03-28T07:11:31-07:00
Authentication code: 8675308
Location: Münster, Germany 52°N,7.6°E

Re: Circular Colour Gradient limited to a Circular Area

Post by whugemann »

Thanks Fred (and Bonzo for the explanation of my needs), this is exactly what I was looking for.

I have been experimenting with masks, but your basic idea to just define plain red as transparent is much brighter. I finally went for the linear gradient with arc distortion, as it gives you somewhat more control over what you are doing. By this way of proceeding it was quite easy to enlarge the yellow centre in the middle.

BTW: I find it quite tedious to provide example images on this board. To my knowledge, I have to upload them to my webite and embed a link over here. This is OK, but then I will have to leave that image there forever, if I don't want to break the thread in retrospective. I would prefer if small images (up to a set size of, say, 20 kB) could be uploaded directly to the discourse server.
Wolfgang Hugemann
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Circular Colour Gradient limited to a Circular Area

Post by anthony »

Using Arc or Polar distortion to generate circular gradients is great, and often easier than using -radial-gradient.
It is also properly sampled (the reverse can not be propelry sampled using EWA (elliptical) resampling

As for displaying images on the forum...

I have a script that I use to simply upload the example to my public dropbox folder, I don't run the drop box client (which syncs the drop box folder to a local disk copy) as I dont want or need a local copy of these images. I just upload and use them. I simply don't care about them after a few months. If I did I would have a local copy anyway. Maybe when I start running out of dropbox space I'll start a new dropbox account, or just junk the lot and start again :-)

Once uploaded (simple command) then have a X window keyboard macro (Window-Ctrl-F3) that writes the URL of my dropbox folder in any input window (such as my forum edit box), and I just append the name of the file and tell the forum editor it is an image. DONE.

EG: For example fom a past upload (a constrained distance gradient example)....
Image
The first part of the image URL is a constant and unchanging, with the filename part is the same as what I uploaded. It does not use the numbered ID or hash's such as other places like flicker.com use.

If I have the dropbox web page open, it also provides pop up menus to get the 'public URL' to the clipboard.

Besides dropbox I also have a private web site, as well as facebook photo albums, and flicker photo sets, that I use for more practical images and screen shots, especially in other things I am involved with. But these I control more carefully than dropbox.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply