Fred's ImageMagick Scripts



    Licensing:

    Copyright © Fred Weinhaus

    My scripts are available free of charge for non-commercial 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

STARBURST


Applies a starburst pattern to an image.

Download Script

last modified: September 26, 2017



USAGE: starburst [-r radius] [-g glow] [-c center] [-k contrast] [-t tcolor] [-b bcolor] [-f fcolor] [-a angle] [-n newseed] [-s size] [infile] outfile
USAGE: starburst [-h or -help]

-r .... radius ........... maximum radius of the starburst pattern;
.......................... integer>0; default is one third the minimum image dimension
-g .... glow ............. radius of the inner glow area as percentage of radius;
.......................... integer; 0<=glow<=100; default=50
-c .... center ........... center point for the halo; center=cx,cy;
.......................... integer>=0; default is center of image
-k .... contrast ......... percent change in contrast for starburst pattern;
.......................... values are positive, zero or negative integers; default=0
-t .... tcolor ........... tint color for starburst; Any valid IM color is allowed;
.......................... The default=white
-f .... fcolor ........... foreground color for starburst; Any valid IM color is allowed;
.......................... The default=white
-b .... bcolor ........... background color for starburst if no input image is provided;
.......................... Any valid IM color is allowed; The default=black
-a .... angle ............ clockwise rotation angle for starburst pattern; integer;
.......................... 0<=angle<=360; default=0
-n .... newseed .......... seed value for random starburst pattern; integer>0;
.......................... default=different pattern each time
-s .... size ............. size of output (WidthxHeight) if no input image provided

PURPOSE: To apply a starburst pattern to an image.

DESCRIPTION: STARBURST applies a radial starburst pattern to an image a given center, radius and glow amount. The user can also control the coloring, contrast and rotation of the starburst pattern. If no input image is provided the script will create an image of the desired size.

ARGUMENTS:

-r radius ... RADIUS is the maximum radius of the starburst pattern. Values are integers>0. The default is one third of the minimum dimension of the image.

-g glow ... GLOW is the radious of inner glow area of the starburst as a percentage of the radius parameter. Values are integers in the range 0<=glow<=100. The default=50.

-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 input image or size specified for the output image.

-k contrast ... CONTRAST is the percent contrast change for the starburst pattern. Values are positive or negative integers. The default=0.

-t tcolor ... TCOLOR is the tint color for the starburst. The default=white. Any valid IM color is allowed. See http://imagemagick.org/script/color.php

-f fcolor ... FCOLOR is the foreground color for the starburst. The default=white. Any valid IM color is allowed. See http://imagemagick.org/script/color.php

-b bcolor ... BCOLOR is the background color for the starburst when no input image is provided. The default=black. Any valid IM color is allowed. See http://imagemagick.org/script/color.php

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

-n newseed ... NEWSEED is the seed value for the random starburst pattern. Values are integers>0. The default is a different pattern each time.

-s size ... SIZE is the WIDTHxHEIGHT of the desired output image if no input image is specified. Any value supplied will be ignored if an input image is specified.

NOTE: The concept and initial example were developed by Anthony Thyssen. See http://www.imagemagick.org/Usage/advanced/#radial_flares. This script is an elaboration on Anthony's original example.

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

No Input Image --- Variation In Radius

Arguments:
-s 100x100 -n 100 -r 25

Arguments:
-s 100x100 -n 100 -r 33

Arguments:
-s 100x100 -n 100 -r 45



No Input Image --- Variation In Glow

Arguments:
-s 100x100 -n 100 -r 33 -g 25

Arguments:
-s 100x100 -n 100 -r 33 -g 50

Arguments:
-s 100x100 -n 100 -r 33 -g 75



No Input Image --- Variation In Contrast

Arguments:
-s 100x100 -n 100 -r 33 -g 50 -c -20

Arguments:
-s 100x100 -n 100 -r 33 -g 50 -c 0

Arguments:
-s 100x100 -n 100 -r 33 -g 50 -c 20

Arguments:
-s 100x100 -n 100 -r 33 -g 50 -c 40



No Input Image --- Variation In Colors

Arguments:
Tint :
-s 100x100 -n 100
-t lightblue

Arguments:
Foreground:
-s 100x100 -n 100
-f lightblue

Arguments:
Tint And Foreground:
-s 100x100 -n 100
-t lightblue -f lightblue

Arguments:
Background:
-s 100x100 -n 100
-b blue

Arguments:
Foreground And Background:
-s 100x100 -n 100
-f red -b blue



No Input Image --- Variation In Angle

Arguments:
Animation -- Increment Angle 30 deg
-s 100x100 -n 100 -a 0
to
-s 100x100 -n 100 -a 330



Starburst On Background Image
http://www.jhlabs.com/ip/filters/SparkleFilter.html

Original

Arguments:
(default)

Arguments:
Tint And Foreground:
-t white -f pink



Starburst On Background Image -- Variation In Tint And Foreground Color

Original

Arguments:
Tint:
-t yellow

Arguments:
Foreground:
-f yellow

Arguments:
Tint And Foreground:
-t yellow -f yellow



What the script does is as follows:

  • Creates starburst pattern as follows:
    • create random values in a 1 row image
    • roll as needed for rotation angle and add foreground and/or background color
    • append remaining rows of background color and motion-blur vertically
    • create central glow taper mask, where taper has shape of cosine raised to 1.5 power
    • use -compose screen so that will only brighten and not darken
    • convert from polar back to rectangular coords
  • Apply starburst to background color or to input image

This is equivalent to the following IM commands.

  • if [ "$infile" != "" ]; then
    ww=`convert $tmpA -ping -format "%[fx:w]" info:`
    hh=`convert $tmpA -ping -format "%[fx:h]" info:`
    else
    ww=$width
    hh=$height
    fi
  • ww=`convert $infile -format "%[fx:w]" info:`
  • hh=`convert $infile -format "%[fx:h]" info:`
  • mwh=`convert xc: -format "%[fx:min($ww,$hh)]" info:`
  • mwh1=`convert xc: -format "%[fx:$mwh-1]" info:`
  • glow1=`convert xc: -format "%[fx:4*$rad*$glow/100]" info:`
  • roll=`convert xc: -format "%[fx:$ww*(360-$angle)/360]" info:`
  • test=`convert xc: -format "%[fx:$contrast<0?0:1]" info:`
  • if [ $test -eq 0 ]; then
    loval=`convert xc: -format "%[fx:abs($contrast)]" info:`
    hival=100
    else
    loval=0
    hival=`convert xc: -format "%[fx:100-$contrast]" info:`
    fi
  • if [ "$center" = "" ]; then
    cx=`convert xc: -format "%[fx:0.5*($ww-1)]" info:`
    cy=`convert xc: -format "%[fx:0.5*($hh-1)]" info:`
    fi
  • ox=`convert xc: -format "%[fx:floor($cx-0.5*($mwh-1))]" info:`
  • oy=`convert xc: -format "%[fx:floor($cy-0.5*($mwh-1))]" info:`
  • if [ `echo "$ox < 0" | bc` -eq 1 ]; then
    ox="$ox"
    else
    ox="+$ox"
    fi if [ `echo "$oy < 0" | bc` -eq 1 ]; then
    oy="$oy"
    else
    oy="+$oy"
    fi
  • if [ "$tcolor" = "white" ]; then
    tint=""
    else
    tint="-fill $tcolor -tint 100%"
    fi
  • convert -size ${mwh}x1 xc: -seed $newseed +noise Random -channel G -separate +channel \
    -roll +${roll}+0 +level-colors $bcolor,$fcolor \
    -size ${mwh}x${mwh1} xc:$bcolor -append -motion-blur ${rad}x65535-90 \
    \( -size ${mwh}x${glow1} gradient:$fcolor-$bcolor -evaluate cos .5 -negate -evaluate pow 1.5 \) \
    -compose screen -composite \
    -distort Polar -1 $tmp0
  • if [ "$infile" = "" ]; then convert \( -size ${ww}x${hh} xc:$bcolor \) \
    \( $tmp0 -level ${loval},${hival}% $tint \) \
    -geometry ${ox}${oy} -composite $outfile
    else
    convert $infile \( $tmp0 -level ${loval},${hival}% $tint \) \
    -geometry ${ox}${oy} -compose screen -composite $outfile
    fi