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.

SURROUNDBLUR


Creates a blurred background region around the input image.

Download Script

last modified: August 20, 2018



USAGE: surroundblur [-r resize] [-b bgsize] [-s smoothing] [-c color] [-t thickness] [-d darkness] [-f fade] [-e extent] [infile] [outfile]

USAGE: surroundblur [h|-help]

-r ... resize ...... resize of input image; WxH in pixels; default is input size
-b ... bgsize ...... blurred background size; WxH in pixels; default is twice the
.................... original input size
-s ... smoothing ... smoothing (blurring) amount; integer>=0; default=50
-c ... color ....... color of border; default=white
-t ... thickness ... thickness of the border; integer>=0; default=0
-d ... darkeness ... darkeness of the shadow; 0<=integer<=100; default=80
-f ... fade ........ fade rate of the shadow; integer>=0; default=3
-e ... extent ...... extent (distance) of the shadow; integer>=0; default=0

.

PURPOSE: To create a blurred background region around the input image.

DESCRIPTION: SURROUNDBLUR creates a blurred background region around the input image. A border and or drop shadow may be added between the image and the blurred background.

ARGUMENTS:

-r resize ... RESIZE of input image expressed as WxH in pixels or in percent as WxH%. The default is the original input size. The resize value should be smaller than the bgsize.

-b bgsize ... BGSIZE is the blurred background size expressed as WxH in pixels or in percent as WxH%. The default is twice the original input size. The bgsize should be larger than the resize.

-s smoothing ... SMOOTHING (blurring) amount to apply to the input to create the background. Values are integers>=0. The default=50.

-c color ... COLOR is the border color. Any valid opaque IM color is allowed. The default=white.

-t thickness ... THICKNESS of the border. Values are integers>0. The default=0 (no border).

-d darkeness ... DARKNESS of the frame shadow. Values are 0<=integer<=100. The default=80.

-f fade ... FADE (rolloff) of the shadow darkness. Values are integer>=0. The default=3.

-e extent ... EXTENT (distance) of the shadow. Values are integer>=0. The default=0 (no shadow).

# NOTE: This script is not designed for images with transparency.

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

Original Image
(source)

Arguments:
defaults
Arguments:
-c white -t 10
Arguments:
-d 80 -f 3 -e 5
Arguments:
-c white -t 10 -d 80 -f 3 -e 5


Example 2

Original Image
(source)

Arguments:
-r 50x50% -b 100x100% -c white -t 10 -d 80 -f 3 -e 5


Example 3

Original Image

Arguments:
-b 600x500 -c white -t 10 -d 80 -f 3 -e 5


What the script does is as follows:

  • Read input and save to mpr: format
  • read the mpr: image and adjust size to bgsize, crop and blur
  • read the mpr: image and adjust size to resize
  • Optionally add a border and/or shadow
  • Combine the images
  • Write the output

  • convert -quiet "$infile" +repage $tmpA1
  • ww=`convert -ping $tmpA1 -format "%w" info:`
  • hh=`convert -ping $tmpA1 -format "%h" info:`
  • if [ "$resize" = "" ]; then
    resize=${ww}x${hh}
    fi
  • if [ "$bgsize" = "" ]; then
    bww=$((2*ww))
    bhh=$((2*hh))
    bgsize=${bww}x${bhh}
    fi
  • convert $tmpA1 -write mpr:img +delete \
    \( mpr:img -resize ${bgsize}^ -crop ${bgsize}+0+0 +repage -blur 0x$smoothing \) \
    \( mpr:img -resize ${resize} -bordercolor "$color" -border $thickness \) \
    \( +clone -background black -shadow ${darkness}x${fade}+${extent}+${extent} \) \
    \( -clone 2,1 -background none -layers merge +repage \) \
    -delete 1,2 \
    -gravity center -compose over -composite "$outfile"