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

VIGNETTE2


Applies a vignette effect to a picture.

Download Script

last modified: June 02, 2015



USAGE: vignette2 [-a amount] [-d dim] [-s shape] [-r round] [-c color] [-m method] [-i] infile outfile
USAGE: vignette2 [-help|-h]

-a ... amount ... vignette amount; blur sigma value; integer≥0; default=25
-d ... dim ...... vignette region boundary; relative size compared to the
................. input image expressed as width,height in percent or pixels;
................. integer>0; if percent, add % symbol; default=90%
-s ... shape .... shape of vignette region boundary; choices are:
................. rectangle, roundrectangle, ellipse or circle;
................. default=roundrectangle
-r ... round .... amount of rounding for roundrectangle; integer>0;
................. default=2*amount
-c ... color .... vignette color; any opaque IM color allowed or "none"
................. for a transparency vignette; default=black
-m ... method ... vignette color compose method; any IM compose method;
................. default=multiply
-i .............. invert the vignette effect from outside to inside

PURPOSE: Applies a vignette effect to a picture.

DESCRIPTION: VIGNETTE2 applies a vignette effect to a picture. The vignette shape may be any of the following: rectangle, roundrectangle, ellipse or circle. This is similar to the way Photoshop does vignetting.

ARGUMENTS:

-a amount ... AMOUNT is the vignette amount expressed as a blur sigma value. Values are integer≥0. The default=25.

-d dim ... DIM are vignette region boundary dimensions relative to the size of the input image expressed as Width,Height in percent or pixels. One or two values may be supplied. If only one, then it will be used for the second dimension if needed. Values are integers>0. If percent, then add % symbol as Width%[,Height%]. Vignette dimensions must not be larger than the image dimensions or 100%. The default=90%.

-s shape ... SHAPE is the shape of the vignette region boundary. The choices are: rectangle (r), roundrectangle (rr), ellipse (e) or circle (c). The default=roundrectangle.

-r round ... ROUND is the amount of rounding for roundrectangle. Values are integers>0. The default=2*amount.

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

-m method ... METHOD is the vignette color compose method. Any IM compose method is allowed. The default=multiply.

-i ... INVERT the vignette effect from outside to inside.

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 Vignette Amount

Original

Arguments:
-a 25 -d 90 -s roundrectangle

Arguments:
-a 50 -d 90 -s roundrectangle



Example 2 -- Variation In Vignette Dimension

Original

Arguments:
-a 25 -d 90 -s roundrectangle

Arguments:
-a 25 -d 80 -s roundrectangle



Example 3 -- Variation In Vignette Shape

Original

Arguments:
-a 25 -d 90 -s rectangle

Arguments:
-a 25 -d 90 -s roundrectangle

Arguments:
-a 25 -d 90 -s ellipse

Arguments:
-a 25 -d 90 -s circle



Example 3 -- Variation In Vignette Darkness

Original

Arguments:
-a 50 -d 80 -s rectangle -c black

Arguments:
-a 50 -d 80 -s rectangle -c gray



Example 4 -- Variation In Vignette Compose Method

Original

Arguments:
-a 25 -d 90 -s roundrectangle -c red -m hardlight
(similar to divide, pinlight, vividlight)

Arguments:
-a 25 -d 90 -s roundrectangle -c red -m minus

Arguments:
-a 25 -d 90 -s roundrectangle -c red -m multiply
(similar to linearburn and colorburn)

Arguments:
-a 25 -d 90 -s roundrectangle -c red -m pegtoplight

Arguments:
-a 25 -d 90 -s roundrectangle -c red -m softlight

Arguments:
-a 25 -d 90 -s roundrectangle -c red -m colordodge
(similar to screen, plus, lineardodge)

Arguments:
-a 25 -d 90 -s roundrectangle -c red -m exclusion
(similar to difference)

Arguments:
-a 25 -d 90 -s roundrectangle -c red -m luminize



Example 5 -- Inversion

Original

Arguments:
-a 25 -d 90 -s roundrectangle -c red -m luminize

Arguments:
-a 25 -d 90 -s roundrectangle -c red -m luminize -i



What the script does is as follows for mode=intensity:

  • Creates a white mask image with a black region centered inside of
    the desired size and shape and then blurs the image by amount.
  • Composites the original image and a solid color image
    of the same size using the mask image with the chosen
    compose method to create the output image

This is equivalent to the following IM commands for dim specified as percent:

  • convert -quiet -regard-warnings "$infile" +repage "$tmpA1"
  • ww=`convert $tmpA1 -format "%w" info:`
  • hh=`convert $tmpA1 -format "%h" info:`
  • cx=`convert xc: -format "%[fx:$ww/2]" info:`
  • cy=`convert xc: -format "%[fx:$hh/2]" info:`
  • dim=`echo "$dim" | sed 's/%//g'`
  • dimx=`echo "$dim" | cut -d, -f1`
  • dimy=`echo "$dim" | cut -d, -f2`
  • if [ "$round" = "" ]; then
    round=$((2*amount))
    fi
  • ww2=`convert xc: -format "%[fx:$dimx*$cx/100]" info:`
  • hh2=`convert xc: -format "%[fx:$dimy*$cy/100]" info:`
  • if [ "$shape" = "rectangle" ]; then
    args="-$ww2,-$hh2 $ww2,$hh2"
    elif [ "$shape" = "roundrectangle" ]; then
    args="-$ww2,-$hh2 $ww2,$hh2 $round,$round"
    elif [ "$shape" = "ellipse" ]; then
    args="0,0 $ww2,$hh2 0,360"
    elif [ "$shape" = "circle" ]; then
    rad=`convert xc: -format "%[fx:min($ww2,$hh2)]" info:`
    args="0,0 $rad,0"
    fi
  • if [ "$invert" = "yes" ]; then
    inversion="-negate -virtual-pixel black"
    else
    inversion="-virtual-pixel white"
    fi
  • convert $tmpA1 \
    \( -clone 0 -fill "$color" -colorize 100% \) \
    \( -clone 0 -fill white -colorize 100% -fill black \
    -draw "translate $cx,$cy $shape $args" \
    $inversion -blur 0x$amount \) \
    -compose $method -composite $outfile