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.

BEVEL


Applies an inner bevel or outer bevel or emboss effect to an image.

Download Script

last modified: December 15, 2018



USAGE: bevel [-w width] [-a azimuth] [-e elevation] [-d depth] [-f form] [-i innermode] [-o outermode] [-s soften] [-t taper] [-b bcolor] [-c colormode] infile outfile
USAGE: bevel [-h or -help]

-w .... width ........... width of border in pixels; same in both dimensions;
......................... integer>0; default=5
-a .... azimuth ......... azimuth angle for light source; 0<=integer<=360;
......................... counterclockwise from positive x axis (East);
......................... default=135 (NorthWest)
-e .... elevation ....... elevation angle for light source; 0<=integer<=90;
......................... upwards from x-y plane; default=30
-d .... depth ........... depth of effect; integer>=0; default=100
-f .... form ............ form of effect; choices are: inner, outer or emboss;
......................... default=inner
-i .... innermode ....... mode for form=inner or emboss; choices are:
......................... hard or smooth; default=hard
-o .... outermode ....... mode for form=outer or emboss; choices are:
......................... raised or lowered; default=raised
-s .... soften .......... softening or smoothing effect; integer>=0; default=0
-t .... taper ........... taper amount for form=outer or emboss; integer>=0;
......................... nominally 0 to 3; default=2 for mode=raised;
......................... default=0 for mode=lowered
-b .... bcolor .......... color for outer bevel or outer bevel part of emboss;
......................... Any valid opaque IM color is allowed; default=gray
......................... color
-c .... colormode ....... colorization mode when bcolor is assigned; choices
......................... are: dark or light; default=dark

PURPOSE: To apply an inner bevel or outer bevel or emboss effect to an image.

DESCRIPTION: BEVEL applies an inner bevel or outer bevel or emboss effect to an image, especially one that has an alpha channel.

ARGUMENTS:

-w width ... WIDTH is the dimensions of bevel/emboss effect. The same value is used in both dimensions. Values are integers greater than 0. The default=5.

-a azimuth ... AZIMUTH is the angle in degrees in the x-y plane measured counterclockwise from EAST to the light source. Values are integers in the range 0<=azimuth<=360. The default=135 (NorthWest).

-e elevation ... ELEVATION is the angle in degrees upwards from the x-y plane to the light source. Values are integers in the range 0<=elevation<=90. The default=30.

-d depth ... DEPTH controls the depth effect. It basically adjust the contrast of the shading in the effect. Values are integers>=0. Larger values increase the depth/contrast and smaller values decrease the depth/contrast. The default=100.

-f form ... FORM of the effect. The choices are: inner, outer or emboss. The default=inner.

-i innermode ... INNERMODE is the mode for form=inner or emboss. The choices are: hard or smooth. The default=hard.

-o outermode ... OUTERMODE is the mode for form=outer or emboss. The choices are: raised or lowered. The default=raised.

-s soften ... SOFTEN is the amount of softening or smoothing in the effect. Values are integer>=0. Nominal values are 0 to about 10. The default=0 (no softening).

-t taper ... TAPER is the rate of tapering for form=outer or emboss. Values are integesr>=0. Nominally, taper is about 0 to 3. Smaller taper means the effect rolls off or tapers faster and is more downward curved. Larger values means the taper rolls off more slowly and flatly. The default=2 for mode=raised and the default=0 for mode=lowered.

-b bcolor ... BCOLOR is the color to apply to the outer bevel or outer bevel part of emboss. Any valid opaque IM color is allowed. The default=gray

-c colormode ... COLORMODE is the colorization mode to use when bcolor is assigned. The choices are: dark or light. The default=dark.

NOTE: When the image has no alpha channel or a fully opaque alpha channel, then it is recommended that one use my bevelborder script, as it is much faster.

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


Original

Arguments:
-w 5 -f inner -i hard
(default)

Arguments:
-w 10 -f inner -i hard

Arguments:
-w 10 -f inner -i hard -s 0

Arguments:
-w 10 -f inner -i hard -s 5

Arguments:
-w 5 -f inner -i smooth

Arguments:
-w 10 -f inner -i smooth

Arguments:
-w 10 -f inner -i smooth -s 0

Arguments:
-w 10 -f inner -i smooth -s 2

Arguments:
-w 10 -f inner -i smooth -s 0

Arguments:
-w 10 -f inner -i smooth -s 5

Arguments:
-w 5 -f outer -o raised

Arguments:
-w 10 -f outer -o raised

Arguments:
-w 10 -f outer -o raised -s 0

Arguments:
-w 10 -f outer -o raised -s 5

Arguments:
-w 10 -f outer -o raised -s 0

Arguments:
-w 10 -f outer -o raised -s 10

Arguments:
-w 10 -f outer -o raised -s 0 -t 2

Arguments:
-w 10 -f outer -o raised -s 0 -t 1

Arguments:
-w 10 -f outer -o raised -s 0 -t 2

Arguments:
-w 10 -f outer -o raised -s 0 -t 0

Arguments:
-w 10 -f outer -o raised -b lightblue -c dark

Arguments:
-w 10 -f outer -o raised -b lightblue -c light

Arguments:
-w 5 -f outer -o lowered

Arguments:
-w 10 -f outer -o lowered

Arguments:
-w 10 -f emboss -i hard -o raised

Arguments:
-w 10 -f emboss -i smooth -o raised

Arguments:
-w 10 -f emboss -i hard -o lowered

Arguments:
-w 10 -f emboss -i smooth -o lowered

Arguments:
-w 10 -f emboss -o raised -b lightblue -c dark

Arguments:
-w 10 -f emboss -o raised -b lightblue -c light



What the script does is as follows (for the case of inner bevel):

  • Keep the alpha channel separate from the image, but
    also flatten the alpha channel into the image
  • Process the alpha channel using -morphology distance
  • Process the distance image using -shade
  • Stretch the shaded image to full dynamic range
    then modify its contrast as desired for the depth
  • Convert the neutral shaded region to mid-gray
    via a mask created by thresholding the alpha channel
  • Composite the modified shaded image with the original
    opaque version of the input image using compose hardlight
  • Put the input imagess original alpha channel back

This is equivalent to the following IM commands for the case of form=inner and imode=hard.

  • convert $infile \( -clone 0 -alpha extract \) \
    \( -clone 0 -background gray -flatten \) -delete 0 +swap \
    -compose copy_opacity -composite $tmpA1
  • wfact=$((1000*$width))
  • leveling="-level 0,$wfact"
  • contr=`convert xc: -format "%[fx:(0.5*$depth-100)]" info:`
  • deepening="-brightness-contrast 0,$contr"
  • softening="-blur ${soften}x65000"
  • convert $tmpA1 -alpha extract -write $tmpA2 \
    +level 0,1000 -white-threshold 999 \
    -morphology Distance:-1 Euclidean:$width,1000 $leveling \
    -shade ${azimuth}x${elevation} \
    -auto-level $deepening $softening \
    \( +clone -fill "gray(50%)" -colorize 100% \) +swap \( $tmpA2 -threshold 0 \) \
    -compose over -composite \
    \( $tmpA1 -alpha off \) +swap -compose hardlight -composite \
    $tmpA2 -alpha off -compose copy_opacity -composite \
    $outfile