Method: Magick::Image#modulate

Defined in:
ext/RMagick/rmimage.c

#modulate(*args) ⇒ Object

Control the brightness, saturation, and hue of an image.

Ruby usage:

- @verbatim Image#modulate @endverbatim
- @verbatim Image#modulate(brightness) @endverbatim
- @verbatim Image#modulate(brightness, saturation) @endverbatim
- @verbatim Image#modulate(brightness, saturation, hue) @endverbatim

Notes:

- Default brightness is 100.0
- Default saturation is 100.0
- Default hue is 100.0
- all three arguments are optional and default to 100%

Parameters:

  • argc

    number of input arguments

  • argv

    array of input arguments

  • self

    this object

Returns:

  • a new image

[View source]

8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
# File 'ext/RMagick/rmimage.c', line 8763

VALUE
Image_modulate(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    double pct_brightness = 100.0,
    pct_saturation = 100.0,
    pct_hue        = 100.0;
    char modulate[100];

    image = rm_check_destroyed(self);
    switch (argc)
    {
        case 3:
            pct_hue        = 100*NUM2DBL(argv[2]);
        case 2:
            pct_saturation = 100*NUM2DBL(argv[1]);
        case 1:
            pct_brightness = 100*NUM2DBL(argv[0]);
            break;
        case 0:
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 0 to 3)", argc);
            break;
    }

    if (pct_brightness <= 0.0)
    {
        rb_raise(rb_eArgError, "brightness is %g%%, must be positive", pct_brightness);
    }
    sprintf(modulate, "%f%%,%f%%,%f%%", pct_brightness, pct_saturation, pct_hue);

    new_image = rm_clone_image(image);

    (void) ModulateImage(new_image, modulate);
    rm_check_image_exception(new_image, DestroyOnError);

    return rm_image_new(new_image);
}