webCOMAND

#IMAGE Shadow

Add a drop-shadow "under" the current image.  Useful when subsequently compositing the image onto another image.

Only supported by ImageMagick image processing engine.

Prototype

#IMAGE($image_bytes, 'Shadow', $x, $y, $opacity, $sigma)

Parameters

x and y parameters do not have an effect in PHP's ImageMagick implementation.
  • x - Horizontal offset in pixels from "center".  A positive number moves the shadow left.  A negative number moves it right.
  • y - Vertical offset in pixels from "center".  A positive number moves the shadow down.  A negative number moves it up.
  • opacity - How "dark" to make the shadow.  0 = transparent.  100 = solid black.
  • sigma - Width of "blur".  0 = tiny/invisible, 4 = pretty wide.

Example

The following example rotates the image before applying the shadow and then rotates it back, to work-around the x/y parameters having no effect (issue with PHP ImageMagick).

#{
    // Add drop-shadow to logo, place it in a white circle with a drop-
    // shadow and overlay that in the upper-right of a banner image
    $CircleDiameter = 512;
    $ShiftX = 6;
    $ShiftY = 3;
    $LogoSize = $CircleDiameter * 0.65;
    $CircleShiftX = $CircleDiameter / $ShiftX;
    $CircleShiftY = $CircleDiameter / $ShiftY * -1;

    // Overlay logo in center of circle
    $Logo = image($Logo,'Shadow',0,0,45,1);
    $LogoWidth = image($Logo,'GetWidth');
    $LogoHeight = image($Logo,'GetHeight');
    $X = ($CircleDiameter / 2) - ($LogoWidth / 2);
    $Y = ($CircleDiameter / 2) - ($LogoHeight / 2);
    $Circle = image($Circle,'Composite',$Logo,$X,$Y,'Dissolve',100);

    // Add drop-shadow to circle (rotate before and after to adjust
    // angle from lower-right to lower-left)
    $Circle = image($Circle,'Rotate',270,'none');
    $Circle = image($Circle,'Shadow',0,0,50,4);
    $Circle = image($Circle,'Rotate',-270,'none');

    // Overlay circle with logo on banner image
    $BannerWidth = image($Banner,'GetWidth');
    $X = $BannerWidth - $CircleDiameter + $CircleShiftX;
    $Y = $CircleShiftY;
    $Banner = image($Banner,'Composite',$Circle,$X,$Y,'Dissolve',100);
}