Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial (non-profit) use, ONLY.

    For use of my scripts in commercial (for-profit) environments or non-free applications, please contact me (Fred Weinhaus) for licensing arrangements. My email address is fmw at alink dot net.

    If you: 1) redistribute, 2) incorporate any of these scripts into other free applications or 3) reprogram them in another scripting language, then you must contact me for permission, especially if the result might be used in a commercial or for-profit environment.

    Usage, whether stated or not in the script, is restricted to the above licensing arrangements. It is also subject, in a subordinate manner, to the ImageMagick license, which can be found at: http://www.imagemagick.org/script/license.php

    Please read the Pointers For Use on my home page to properly install and customize my scripts.

HALO


Applies a circular halo to an image.

Download Script

last modified: December 15, 2018



USAGE: halo [-r radius] [-w width] [-c center] [-o opacity] [-k contrast] [-m mixture] [-b basecolor] [-s saturation] [-a angle] [-d density] [-n newseed] [-f feather] infile outfile
USAGE: halo [-h or -help]

-r .... radius ........... radius from center point to beginning of halo;
.......................... integer>=0; default is one quarter the minimum image dimension
-w .... width ............ width or distance of halo to outer radius; integer>0;
.......................... default is one quarter the minimum image dimension
-c .... center ........... center point for the halo; center=cx,cy;
.......................... integer>=0; default is center of image
-o .... opacity .......... opacity of the halo; integer; 0<=opacity<=100;
.......................... opacity=100 is fully opaque; opacity=0 if fully transparent;
.......................... default=40
-k .... contrast ......... contrast of of halo striations; integer 0<=contrast<=100;
.......................... contrast=0 is no striations; contrast=100 is fully transparent
.......................... gaps between striations; default=50
-m .... mixture .......... mixture of primary colors from the base color; integer;
.......................... 0<=mixture<=100; mixture=0 is full separation of primary colors;
.......................... mixture=100 is full overlap of primary colors causing a solid halo
.......................... of the basecolor; mixture=25 is a nice even full rainbow halo;
.......................... default=65 is a non-rainbow halo of subdued colors
-b .... basecolor ........ base color for for the halo from which its primary colors
.......................... will be extracted. Any valid IM color is allowed.
.......................... The default="rgb(100%,90%,80%)"
-s .... saturation ....... saturation of the halo colors; integer; 0<=saturation<=100;
.......................... default=100
-a .... angle ............ clockwise rotation angle for striation patteren; integer;
.......................... 0<=angle<=360; default=0
-d .... density .......... density of random striation pattern; integer; 0<=density<=100;
.......................... Larger values have smaller gaps and smaller values have larger gaps;
.......................... The default=40
-n .... newseed .......... seed value for random striation pattern; integer>0; default=100
-f .... feather .......... feather or blurring distance of inner and outer halo radii;
.......................... integer>=0; default=10

PURPOSE: To apply a circular halo to an image.

DESCRIPTION: HALO applies a circular halo of given center, inner radius and width to outer radius. The user can also control the coloring of the halo, its striation contrast, its overall transparency and saturation and rotation of the halo striation pattern.

ARGUMENTS:

-r radius ... RADIUS is the radius from center point to beginning of halo. Values are integers>=0. The default is one quarter of the minimum dimension of the image.

-w width ... WIDTH is the distance of halo to outer radius. Values are integers>0. The default is one quarter of the minimum dimension of the image. Note: the halo will start to fade out for widths less than or equal to the feather amount.

-c center ... CENTER=cx,cy are the comma separated coordinates in the image determining the center of the halo. Values are integers>=0. The default is the center of the image.

-o opacity ... OPACITY is the opacity of the halo. Values are integers, such that 0<=opacity<=100. An opacity=100 is fully opaque. An opacity=0 if fully transparent. The default=40.

-k contrast ... CONTRAST is the contrast of the halo striations. Values are integers, such that 0<=contrast<=100. A contrast=0 is no striations. A contrast=100 is fully transparent gaps between striations. The default=50.

-m mixture ... MIXTURE is the halo mixture of primary colors from the base color. Values are integers such that 0<=mixture<=100. A mixture=0 is full separation of primary colors. A mixture=100 is full overlap of primary colors causing a solid halo color of the basecolor. A mixture=25 is a nice even full rainbow halo. The default=65 is a non-rainbow halo of subdued colors.

-b basecolor ... BASECOLOR is the base color for the halo from which its primary colors will be extracted. Any valid IM color is allowed, but should not have zero percent of either red, green or blue primary components. The default="rgb(100%,90%,80%)". See http://imagemagick.org/script/color.php

-s saturation ... SATURATION is the saturation of the halo colors. Values are integer such that 0<=saturation<=100. The default=100.

-a angle ... ANGLE is the clockwise rotation angle for the halo striation pattern. Values are integers such that 0<=angle<=360. The default=0.

-d density ... DENSITY is the density of random striation pattern in the halo. Values are integers such that 0<=density<=100. Larger values have smaller gaps between striations and smaller values have larger gaps between striations. Thus at contrast=100 and density=0, there is no halo (i.e, fully transparent). And at contrast=100 and density=100 there is a solid halo with no striations. The default=40.

-n newseed ... NEWSEED is the seed value for the random striations. Values are integers>0. The default=100.

-f feather ... FEATHER is the feathering or blurring distance at the inner and outer halo radii. Values are integer>=0; The default=10.

NOTE: Requires IM 6.4.2-8 or higher due to the use of -distort polar/depolar.

CAVEAT: No guarantee that this script will work on all platforms, nor that trapping of inconsistent parameters is complete and foolproof. Use At Your Own Risk.


EXAMPLES

Example 1

Original

Arguments:
-r 60 -w 60 -m 65 -c 127,100

Arguments:
-r 60 -w 60 -m 25 -c 127,100

Animation
-r 60 -w 60 -m 25 -c 127,100
-a varied from 0 to 330 in 30 degree steps



Example 2

Original

Arguments:
-r 60 -w 60 -m 65 -o 40 -c 140,100

Arguments:
-r 60 -w 60 -m 25 -o 30 -c 140,100



Gray Background --- Variation In Opacity

Arguments:
-r 40 -w 60 -m 25 -o 20

Arguments:
-r 40 -w 60 -m 25 -o 40

Arguments:
-r 40 -w 60 -m 25 -o 60

Arguments:
-r 40 -w 60 -m 25 -o 100



Gray Background --- Variation In Striation Contrast

Arguments:
-r 40 -w 60 -m 25 -o 100 -k 0

Arguments:
-r 40 -w 60 -m 25 -o 100 -k 50

Arguments:
-r 40 -w 60 -m 25 -o 100 -k 100



Gray Background --- Variation In Color Mixture

Arguments:
-r 40 -w 60 -m 0 -o 100

Arguments:
-r 40 -w 60 -m 25 -o 100

Arguments:
-r 40 -w 60 -m 65 -o 100

Arguments:
-r 40 -w 60 -m 100 -o 100



What the script does is as follows:

  • Creates a vertically oriented color halo image according to the mixture and width parameters
  • Pads with black at the top and bottom to set the inner and outer radii
  • Creates a horizontally random striation mask
  • Creates a feather mask, blurred at the top and bottom of the halo
  • Composites the striation and feather masks
  • Puts the composite mask into the alpha channel of the vertical halo image
  • Converts the halo image from polar coordinates to rectangular coordinates
  • Composites the original image with the transformed halo image

This is equivalent to the following IM commands

  • contr=`convert xc: -format "%[fx:$opacity*(1-$contrast/100)]" info:`
  • dens=`convert xc: -format "%[fx:100-$density]" info:`
  • roll=`convert $infile -format "%[fx:w*(360-$angle)/360]" info:`
  • ratio=`convert $infile -format "%[fx:2*h/sqrt(w*w+h*h)]" info:`
  • rad2=`convert $infile -format "%[fx:floor($ratio*$rad)]" info:`
  • width2=`convert $infile -format "%[fx:floor($ratio*$width)]" info:`
  • ww=`convert $infile -format %w info:`
  • hh=`convert $infile -format %h info:`
  • hmrw=`convert xc: -format "%[fx:max(1,$hh-$rad2-$width2)]" info:`
  • red=`convert -size 1x1 xc:$bcolor -format "%[fx:100*u.r]" info:`
  • green=`convert -size 1x1 xc:$bcolor -format "%[fx:100*u.g]" info:`
  • blue=`convert -size 1x1 xc:$bcolor -format "%[fx:100*u.b]" info:`
  • mix2=`convert xc: -format "%[fx:66.7*(100-$mixture)/100]" info:`
  • convert \( -size 1x${width2} gradient: -threshold $mix2% -fill "gray($blue%)" -opaque white \) \
    \( -clone 0 \( -clone 0 -flip \) +swap -append -resize 1x${width2}! -fill "gray($green%)" -opaque white \) \
    \( -clone 0 -flip -fill "gray($red%)" -opaque white \) \
    -reverse -combine \
    -resize 1x${size} -resize ${ww}x${width2}! \
    -modulate 100,$sat,100 \
    $tmp1
  • convert \( -size ${ww}x${rad2} xc:black \) \
    $tmp1 \
    \( -size ${ww}x${hmrw} xc:black \) -append \
    -crop ${ww}x${hh}+0+0 +repage \
    -modulate 100,${sat},100 \
    $tmp1
  • convert \( -size ${ww}x${rad2} xc:black \) \
    \( -size ${ww}x1 xc: -seed $newseed +noise random -channel G -separate +channel \
    -threshold $dens% -scale ${ww}x${width2}! -roll +${roll}+0 +level ${contr}x${opacity}% \) \
    \( -size ${ww}x${hmrw} xc:black \) -append \
    -crop ${ww}x${hh}+0+0 +repage \
    $tmp2
  • convert \( -size ${ww}x${rad2} xc:black \) \
    \( -size ${ww}x${width2} xc:white \) \
    \( -size ${ww}x${hmrw} xc:black \) -append \
    -crop ${ww}x${hh}+0+0 +repage \
    -blur ${feather}x65535 -level 50x100% \
    $tmp3
  • convert $tmp2 $tmp3 -compose multiply -composite $tmp2
  • convert $tmp1 $tmp2 -compose copy_opacity -composite $tmp1
  • convert $tmp1 -distort polar -1,0,$cx,$cy $tmp1
  • convert $infile $tmp1 -composite $outfile