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.

IMAGEBORDER


Appends an image border by extending the outer regions of the image.

Download Script

last modified: December 15, 2018



USAGE: imageborder [-s size] [-b blurring] [-m mixcolor] [-p percent] [-r rimcolor] [-t thickness] [-e effect] [-f framebevel] [-c contrast] infile outfile
USAGE: imageborder [-h or -help]

-s .... size ............ size of border; WidthxHeight; default equals 10%
......................... of min(imagewidth, imageheight) in both dimensions
-b .... blurring ........ blurring amount for border effect; integer>=0;
......................... default=3
-m .... mixcolor ........ color to mix with the image border; default=white
-p .... percent ......... mixing percent for the mixcolor; 0<=integer<=100;
......................... default=30
-r .... rimcolor ........ rim color between the original image and the image
......................... border; any valid IM color is allowed; default=white
-t .... thickness ....... rim thickness; integer>=0; default=1
-e .... effect .......... image border effect; choices are edge, mirror,
......................... magnify, tile or random; default=edge
-f .... framebevel ...... frame bevel type to apply; choices are: inner,
......................... outer or split. The default is no bevel
-c .... contrast ........ contrast percent for bevels; 0<=integer<=100;
......................... default=50

PURPOSE: To append an image border by extending the outer regions of the image.

DESCRIPTION: IMAGEBORDER appends an image border by extending the outer regions of the image. Thus the output image will be larger than the input image and no area of the input image will be covered. The extended border can be blurred, mixed with some other color and can either extend the outer row and column or mirror the outer area of the image to create the border effect. A rim color can also be placed around the original image.

ARGUMENTS:

-s size ... SIZE (WidthxHeight) is the size or dimensions of the border region. Values are integers greater than 0. Size can be specified as one value that will be used all around or as two values delimeted with an "x". The first value will be the border size in the width dimension and the second will be the border size in the height dimension. The default is to use one value all around that is 10% of the min(width,height) of the image.

-b blurring ... BLURRING is the amount of blur to apply to the border region. Values are integers>=0. The default=3

-m mixcolor ... MIXCOLOR is the color to mix with the image border. Any valid IM color may be used. The default is white.

-p percent ... PERCENT is the percent of the mixcolor to blend with the image border. Values are integers such that 0<=percent<=100. The default is 30.

-r rimcolor ... RIMCOLOR is the color of the rim to place around the original image. Any valid IM color may be used. The default is white.

-t thickness ... THICKNESS is the thickness of the rim around the original image. Values are integers>=0. The default=1.

-e effect ... EFFECT specifies the type of image border effect to use. The choices are edge, mirror, magnify, tile or random. If edge is specified, then the top, right, bottom and left row/column of the image will simply be extended by the size parameters to create the image border. If mirror is specified, then the outer size pixels from the image will be mirrored to produce the image border effect. If magnify is specified, then the border will be created from the magnified image. If tile is specified, then the border will be created from tiling the image. If random is specified, then the border will be made up of random pixels from the image The default is edge.

-f framebevel ... FRAMEBEVEL is the type of bevel to apply over the effect. The choices are: outer (i.e. raised), inner (i.e. depressed) or split (half and half). The default is no bevel.

-c contrast ... CONTRAST percent for innerbevel or outerbevel. Values are integers between 0 and 100. The default=50.

NOTE: Requires IM 6.3.5-4 or higher due to the use of -distort SRT

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:
-b 3 -m white -p 30 -r white -t 1 -e edge
(default)

Arguments:
-b 3 -m pink -p 30 -r white -t 1 -e edge

Arguments:
-b 3 -m skyblue -p 30 -r white -t 1 -e edge

Arguments:
-b 3 -m white -p 30 -r white -t 1 -e edge
(default)

Arguments:
-b 3 -m white -p 30 -r black -t 1 -e edge

Arguments:
-b 3 -m white -p 30 -r white -t 0 -e edge

Arguments:
-b 3 -m white -p 30 -r white -t 1 -e edge
(default)

Arguments:
-b 3 -m white -p 30 -r white -t 1 -e mirror

Arguments:
-b 3 -m white -p 30 -r white -t 1 -e magnify

Arguments:
-b 0 -m white -p 30 -r white -t 1 -e random

Arguments:
-b 1 -m white -p 30 -r white -t 1 -e random

Arguments:
-b 3 -m white -p 30 -r white -t 1 -e random

Arguments:
-b 0 -m white -p 30 -r white -t 1 -e dither

Arguments:
-b 1 -m white -p 30 -r white -t 1 -e dither

Arguments:
-b 3 -m white -p 30 -r white -t 1 -e dither

Arguments:
-b 3 -m white -p 30 -r white -t 1 -e tile

Arguments:
-b 3 -m white -p 30 -r white -t 1 -e average

Arguments:
-b 0 -m white -p 0 -r white -t 1 -e average

Arguments:
-b 3 -m white -p 30 -r blue -t 1 -e edge -f outer

Arguments:
-b 3 -m white -p 30 -r blue -t 1 -e edge -f inner

Arguments:
-b 3 -m white -p 30 -r blue -t 1 -e edge -f split



What the script does is as follows:

  • Uses -distort SRT with the specified virtual-pixel effect
    to enlarge, blur and colorize a copy of the image
  • Composes the original image with a border around it over
    the center of the distorted copy

This is equivalent to the following IM commands.

  • wd=`convert $infile -ping -format "%w" info:`
  • ht=`convert $infile -ping -format "%h" info:`
  • ww=`convert xc: -format "%[fx:$wd+2*$wsize]" info:`
  • hh=`convert xc: -format "%[fx:$ht+2*$hsize]" info:`
  • if [ "$effect" = "magnify" ]; then
    effect="edge"
    xmag=`convert xc: -format "%[fx:$ww/$wd]" info:`
    ymag=`convert xc: -format "%[fx:$hh/$ht]" info:`
    else
    xmag=1
    ymag=1
    fi
  • if [ "$effect" = "random" -o "$effect" = "dither" ]; then
    blurring1=""
    blurring2="-blur 0x${blurring}"
    else
    blurring1="-blur 0x${blurring}"
    blurring2=""
    fi
  • if [ "$effect" = "average" ]; then
    effect="background"
    bgcolor=`convert \( zelda3.jpg -scale 1x1! \) -format \
    "rgb(%[fx:100*u.p{0,0}.r]%%,%[fx:100*u.p{0,0}.g]%%,%[fx:100*u.p{0,0}.b]%%)" info:`
    backgroundcoloring="-background $bgcolor" colorization1=""
    colorization2="-fill $mixcolor -colorize ${percent}%"
    else
    backgroundcoloring="" colorization1="-fill $mixcolor -colorize ${percent}%"
    colorization2=""
    fi
  • convert $infile \ \( -clone 0 $blurring1 $colorization1 \
    -set option:distort:viewport ${ww}x${hh}-${wsize}-${hsize} \
    $backgroundcoloring -virtual-pixel $effect \ -distort SRT "0,0 $xmag,$ymag 0" $blurring2 $colorization2 \) \
    \( -clone 0 -bordercolor $rimcolor -border $thickness \) \
    -delete 0 -gravity center -compose over -composite \
    $outfile