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.

SOFTFOCUS


Applies a softfocus effect to an image.

Download Script

last modified: December 15, 2018



USAGE: softfocus [-m mix] [-b bluramt1] [-B bluramt2] [-o opacity1] [-O opacity2] [-c coords] [-r radius] infile outfile
USAGE: softfocus [-h or -help]

-m ... mix ......... mix percent between compose softlight and compose over
.................... approaches; mix=0 is softlight, mix=100 is over;
.................... 0<=integer<=100; default=50 (equal blend of the two)
-b ... bluramt1 .... blur amount when using the compose softlight method;
.................... float>=0;default=4
-B ... bluramt2 .... blur amount when using the compose over method; float>=0;
.................... default is automatically computed from the image size
-o ... opacity1 .... opacity amount when using the compose softlight method;
.................... 0<=integer<=100; default=50
-O ... opacity2 .... opacity amount when using the compose over method;
.................... 0<=integer<=100; default=50
-c ... coords ...... x,y center coordinates for the no blur region when
.................... using compose over approach; integers>=0;
.................... default=image center
-r ... radius ...... percent of minimum distance between coords and edges of
.................... image for the no blur center region when method is over;
.................... 0<=integer<=100; default=25

PURPOSE: To apply a softfocus effect to an image.

DESCRIPTION: SOFTFOCUS appliesa softfocus effect to an image. This will be a blend of two methods. One used -compose softlight and the other uses -compose over. The latter applies a ramped blur and allows a center region with no blur.

ARGUMENTS:

-m mix ... MIX is the mix percent between compose softlight and compose over methods. Mix=0 is -compose softlight and mix=100 is -compose over. Values are integers between 0 and 100. The default=50 (equal blend of the two methods).

-b bluramt1 ... BLURAMT1 is the blur amount when using the compose softlight method. Values are floats>=0. The default=4.

-B bluramt2 ... BLURAMT2 is the blur amount when using the compose over method. Values are floats>=0. The default is automatically computed from the image size.

-o opacity1 ... OPACITY1 is the opacity amount when using the compose softlight method. Values are integers between 0 and 100. The default=50.

-O opacity2 ... OPACITY2 is the opacity amount when using the compose over method. Values are integers between 0 and 100. The default=50.

-c coords ... COORDS are the x,y center coordinates for the no blur region when using the compose over method. Values are integers>=0. The default is the image center.

-r radius ... RADIUS is the percent of the minimum distance between the specified coords and the edges of image. This radius computes the size of the no blur center region when the method is over. Values are integers between 0 and 100. The default=25. When no coords are specified the ramped blur will have an elliptical shape if the image is not square; otherwise, it will be a circle. It will always be a circle, if coords are specified.

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 -- Equal Blend of Compose Softlight and Compose Over

Original
(http://www.onlyphotoshop.com/tutorial/soft-focus-effect-techniques/14/)

Arguments:
-m 50 -o 50 -O 50
(default)

Arguments:
-m 50 -o 50 -O 100



Example 2 -- Variation In Opacity For Compose Softlight

Original

Arguments:
-m 0 -o 50

Arguments:
-m 0 -o 100



Example 2 -- Variation In Opacity For Compose Over

Original

Arguments:
-m 100 -O 50

Arguments:
-m 100 -O 100



What the script does is as follows:

  • Creates a blurred version of the image with desired opacity
  • Composes the original image with the blurred version using -compose softlight
  • Creates another blurred version of the image with desired opacity
  • Creates a negated radial gradient and uses -black-threshold to
    make some center region full black (for full transparency)
  • Creates a mask from a negated radial gradient and uses -black-threshold to
    make some center region full black (for full transparency)
  • Composes the original image with the blurred version and the mask using -compose over
  • Blends the two composited results together

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

  • ww=`identify -ping -format "%w" $infile`
  • hh=`identify -ping -format "%h" $infile`
  • min=`convert xc: -format "%[fx:min($ww,$hh)]" info:`
  • max=`convert xc: -format "%[fx:max($ww,$hh)]" info:`
  • bluramt2=`convert xc: -format "%[fx:max(1.5,1.5*($max/250))]" info:`
  • convert $infile \
    \( -clone 0 -blur 0x$bluramt -alpha set -channel A -evaluate set ${opacity1}% +channel \) \
    -compose softlight -composite $dir/tmpSL.mpc
  • convert -size ${min}x${min} radial-gradient: -negate \
    -resize ${ww}x${hh}\! -black-threshold $radius% -level $gthresh%,100% $dir/tmpG.mpc
  • convert $dir/tmpI.mpc \
    \( -clone 0 -blur 0x$bluramt2 -alpha set -channel A -evaluate set ${opacity2}% +channel \) \
    $dir/tmpG.mpc -compose over -composite $dir/tmpO.mpc
  • convert $dir/tmpSL.mpc $dir/tmpO.mpc -define compose:args=$mix% \
    -compose blend -composite $outfile