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.

VIGNETTE3


Applies a vignette effect to a picture.

Download Script

last modified: December 16, 2018



USAGE: vignette3 [-d diameter] [-x xycenter] [-c] [-o outramp] [-i inramp]
[-g gamma] [-v vcolor] [-b bright] [-s sat] infile outfile

USAGE: vignette3 [-help|-h]

-d ... diameter .... vignette region boundary; relative size compared to the
.................... input image expressed as width,height in percent;
.................... integer>0; default=70
-x ... xycenter .... x,y center of vignette; comma separate pair; integers>=0;
.................... default is center of image
-c ... circle ...... constrain shape to circle rather than ellipse for
.................... non-square image; default is no constraint
-o ... outramp ..... vignette outer ramp extent; -100<=integer<=100;
.................... larger values lengthen the ramp and shorter values
.................... shorten the ramp; default is linear ramp to most
.................... distant image point.
-i ... inramp ...... vignette inner ramp extent in pixels; integer>=0;
.................... the default=0
-g ... gammma ...... gamma adjustment of shape of ramps; gamma>=0; values less
.................... than 1 lengthen the ramps and values larger than 1
.................... shorten the ramp; default=1
-v ... vcolor ...... vignette color; any opaque IM color allowed or "none"
.................... for a transparency vignette; default=black
-b ... bright ...... brightness change of image under the vignette;
.................... -100<=integer<=100; default=0 (no change)
-s ... sat ......... saturation change of image under the vignette;
.................... -100<=integer<=100; default=0 (no change)

PURPOSE: Applies a vignette effect to a picture.

DESCRIPTION: VIGNETTE3 applies a vignette effect to a picture. The vignette center may be moved.

ARGUMENTS:

-d diameter ... DIAMETER controls the vignette region boundary. It is expressed as a percentage of the input image width,height. Values are integers>0. The default=70

-x xycenter ... XYCENTER specify the x,y center of the vignette effect. Values are a comma separate pair of integers>=0. The default is center of image.

-c circle ... CIRCLE indicates to constrain the shape to a circle rather than an ellipse for non-square image. The default=no constraint

-o outramp ... OUTRAMP is the vignette linear outer ramp extent. Values are -100<=integer<=100. Larger values lengthen the ramp and shorter values shorten the ramp. The default is a linear ramp tapering to zero at the most distant image point.

-i inramp ... INRAMP is the vignette inner ramp extent in pixels. Value are 0<=integer<=100. The default=0.

-g gammma ... GAMMA adjusts the shape (and length) of the ramps. Values are floats>=0. Values less than 1 lengthen the ramps and values larger than 1 shorten the the ramp. The default=1.

-v vcolor ... VCOLOR is the vignette color. Any opaque IM color is allowed or "none" for a transparency vignette effect, The default=black.

-b bright ... BRIGHT is the brightness change of the image under the vignette. Values are -100<=integer<=100. The default=0 (no change).

-s sat ... SAT is the saturation change of the image under the vignette. Values are -100<=integer<=100. The default=0 (no change).

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 -- Variation In Diameter

Original

Arguments:
-d 50

Arguments:
-d 70

Arguments:
-d 100



Example 2 -- Variation In Outer Ramp

Original

Arguments:
-d 70 -o -40

Arguments:
-d 70 -o 0

Arguments:
-d 70 -o 40



Example 3 -- Variation In Gamma

Original

Arguments:
-d 70 -g 1.5

Arguments:
-d 70 -g 1

Arguments:
-d 70 -g 0.5



Example 4 -- Variation In Outer Ramp With Circle Constraint

Original

Arguments:
-d 70 -o -40 -c

Arguments:
-d 70 -o 0 -c

Arguments:
-d 70 -o 40 -c



Example 5 -- Variation In Inner Ramp

Original

Arguments:
-d 75 -g 1.5

Arguments:
-d 75 -g 1



Example 6 -- Variation In Circle Center

Original

Arguments:
-d 50 -c

Arguments:
-d 50 -c -x "120,144"



Example 7 -- Variation In Brightness

Original

Arguments:
-d 70 -b 0

Arguments:
-d 70 -b 20



Example 8 -- Variation In Saturation

Original

Arguments:
-d 70 -s 0

Arguments:
-d 70 -s 50



Example 8 -- Variation In Vignette Color

Original

Arguments:
-d 70 -v black

Arguments:
-d 70 -v midnightblue



What the script does is as follows:

  • Brightens and/or saturates the input image
  • Creates a black ellipse on white background as a mask and blurs it and adjusts it's gamma
  • Creates a black image
  • Composites the brightened/saturate image with the original using the ellipse mask
  • Composite the previous composite with the constant vignette color image using ellipse mask

This is equivalent to the following IM commands:

  • convert -quiet -regard-warnings "$infile" +repage "$tmpA1"
  • ww=`convert $tmpA1 -format "%w" info:`
  • hh=`convert $tmpA1 -format "%h" info:`
  • ww2=`convert xc: -format "%[fx:($ww/2)*$diameter/100]" info:`
  • hh2=`convert xc: -format "%[fx:($hh/2)*$diameter/100]" info:`
  • args="0,0 $ww2,$hh2 0,360"
  • blackthresh="-black-threshold $diameter% -level $diameter%,100%"
  • bright=`convert xc: -format "%[fx:$bright+100]" info:`
  • saturate=`convert xc: -format "%[fx:$saturate+100]" info:`
  • inramping="-blur ${inramp}x65000"
  • rampval=`convert xc: -format "%[fx:100-abs($outramp)]" info:`
  • test=`convert xc: -format "%[fx:sign($outramp)<0?0:1]" info:`
  • if [ $test -eq 0 ]; then
    leveling="-level 0x$rampval%"
    else
    leveling="+level 0x$rampval%"
    fi
  • convert $tmpA1 \
    \( -clone 0 -modulate ${bright},${saturate},100 \) \
    \( -clone 0 -fill white -colorize 100% -fill black \
    -draw "translate $xc,$yc ellipse $args" -alpha off -morphology Distance Euclidean:4 \
    -auto-level $leveling $inramping -gamma $gamma +write 2tmp2.jpg \) \
    \( -clone 0 -fill $vcolor -colorize 100% \) \
    \( -clone 1 -clone 0 -clone 2 -compose over -composite \) \
    -delete 0,1 -reverse $setcspace -compose over -composite $outfile