Method: Magick::Image#shadow

Defined in:
ext/RMagick/rmimage.cpp

#ImageMagick::Image

Call ShadowImage. X- and y-offsets are the pixel offset. Alpha is either a number between 0 and 1 or a string “NN%”. Sigma is the std. dev. of the Gaussian, in pixels.

Returns a new image.

Parameters:

  • x_offset (Numeric)

    The shadow x-offset

  • y_offset (Numeric)

    The shadow y-offset

  • sigma (Numeric)

    The standard deviation of the Gaussian operator used to produce the shadow. The higher the number, the “blurrier” the shadow, but the longer it takes to produce the shadow. Must be > 0.0.

  • alpha (Numeric, String)

    The percent alpha of the shadow. The argument may be a floating-point numeric value or a string in the form “NN%”.

Returns:



12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
# File 'ext/RMagick/rmimage.cpp', line 12984

VALUE
Image_shadow(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    double alpha = 100.0;
    double sigma = 4.0;
    long x_offset = 4L;
    long y_offset = 4L;
    ExceptionInfo *exception;

    image = rm_check_destroyed(self);
    switch (argc)
    {
        case 4:
            alpha = rm_percentage(argv[3], 1.0);   // Clamp to 1.0 < x <= 100.0
            if (fabs(alpha) < 0.01)
            {
                rb_warning("shadow will be transparent - alpha %g very small", alpha);
            }
            alpha = FMIN(alpha, 1.0);
            alpha = FMAX(alpha, 0.01);
            alpha *= 100.0;
        case 3:
            sigma = NUM2DBL(argv[2]);
        case 2:
            y_offset = NUM2LONG(argv[1]);
        case 1:
            x_offset = NUM2LONG(argv[0]);
        case 0:
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 4)", argc);
            break;
    }

    exception = AcquireExceptionInfo();
    GVL_STRUCT_TYPE(ShadowImage) args = { image, alpha, sigma, x_offset, y_offset, exception };
    new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(ShadowImage), &args);
    rm_check_exception(exception, new_image, DestroyOnError);
    DestroyExceptionInfo(exception);

    return rm_image_new(new_image);
}