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.

COSINEBELL


Creates a cosine-bell-shaped tapered alpha channel in an image and optionally blends the image into a background image.

Download Script

last modified: December 15, 2018



USAGE: cosinebell [-r rolloff] [-g gravity] [-o offsets] infile1 [infile2] outfile
USAGE: cosinebell [-h or -help]

-r ... rolloff ... rolloff percent (percent distance from the center of the
.................. image to the image edge where the alpha channel drops to
.................. 50% amplitude; 0<=integer<=100; default=30
-g ... gravity ... gravity setting for compositing the smaller image into
.................. the larger image; any valid IM gravity setting is allowed;
.................. default=northwest
-o ... offsets ... x and y offsets relative to the gravity for compositing
.................. the smaller image into the larger image; geometry-like
.................. values, +-X+-Y in pixels; default=+0+0

infile1 is the smaller foreground image and infile2 is the larger background image.

PURPOSE: Creates a cosine-bell-shaped tapered alpha channel in an image and optionally blends the image into a background image.

DESCRIPTION: COSINEBELL creates a cosine-bell-shaped tapered alpha channel in an image and optionally blends the image into a background image.

ARGUMENTS:

-r rolloff ... ROLLOFF (taper) percent (percent distance from the edge of the image to the image center where the alpha channel drops to 50% amplitude. Values are 0<=integer<=100. Nominal values are 10 to 30. The default=30.

-g gravity ... GRAVITY setting for compositing the smaller image into the larger image. Any valid IM gravity setting is allowed. The default=northwest.

-o offsets ... x and y OFFSETS relative to the gravity for compositing the smaller image into the larger image. These are geometry-like values, +-X+-Y in pixels. The default=+0+0

The foreground (infile1) must not be larger than the background image (infile2).

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 -- Tapered Image

Original Image

Arguments:
-r 30 (default)
Extracted Alpha Channel
Profile Of Row 240
Profile Of Column 320


Example 2 -- Variation in Rolloff

Original Image

Arguments:
-r 10
Arguments:
-r 30 (default)
Arguments:
-r 50


Example 3 -- Composite of Two Images

Image 1 (Foreground Image)

Image 2 (Background Image)

Composite Image

-r 30 -g center -o +0+0



What the script does is as follows:

  • Creates a cosine bell tapered image of the size of the first image
  • Puts that into the alpha channel of the first image
  • Optionally, composites the first image onto the second image

This is equivalent to the following IM commands for the two image composite:

  • w1=`convert $infile1 -ping -format "%w" info:`
  • h1=`convert $infile1 -ping -format "%h" info:`
  • convert $infile1 \ \( -clone 0 -crop ${w1}x1+0+0 +repage -fx "0.5*cos(pi*max(0,(1-i/($ff*(w-1)))))+0.5" \
    -scale ${w1}x${h1}! -write mpr:tmp0 +delete \) \
    \( mpr:tmp0 -flop -write mpr:tmp1 +delete \) \
    \( -clone 0 -crop 1x${h1}+0+0 +repage -fx "0.5*cos(pi*max(0,(1-j/($ff*(h-1)))))+0.5" \
    -scale ${w1}x${h1}! -write mpr:tmp2 +delete \) \
    \( mpr:tmp2 -flip -write mpr:tmp3 +delete \) \
    \( mpr:tmp0 mpr:tmp1 -compose multiply -composite \
    mpr:tmp2 -compose multiply -composite \
    mpr:tmp3 -compose multiply -composite \) \
    -compose over -compose copy_opacity -composite \
    $infile2 +swap -gravity $gravity -geometry $offsets -compose over -composite "$outfile"