Method: Magick::Image#splice

Defined in:
ext/RMagick/rmimage.cpp

#splice(x, y, width, height, color = self.background_color) ⇒ Magick::Image

Splice a solid color into the part of the image specified by the x, y, width, and height arguments. If the color argument is specified it must be a color name or Pixel.

Returns a new image.

Parameters:

  • x (Numeric)

    Describe the rectangle to be spliced.

  • y (Numeric)

    Describe the rectangle to be spliced.

  • width (Numeric)

    Describe the rectangle to be spliced.

  • height (Numeric)

    Describe the rectangle to be spliced.

  • color (Magick::Pixel, String) (defaults to: self.background_color)

    The color to be spliced.

Returns:

See Also:



13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
# File 'ext/RMagick/rmimage.cpp', line 13602

VALUE
Image_splice(int argc, VALUE *argv, VALUE self)
{
    Image *image, *new_image;
    PixelColor color, old_color;
    RectangleInfo rectangle;
    ExceptionInfo *exception;

    image = rm_check_destroyed(self);

    switch (argc)
    {
        case 4:
            // use background color
            color = image->background_color;
            break;
        case 5:
            // Convert color argument to PixelColor
            Color_to_PixelColor(&color, argv[4]);
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 4 or 5)", argc);
            break;
    }

    rectangle.x      = NUM2LONG(argv[0]);
    rectangle.y      = NUM2LONG(argv[1]);
    rectangle.width  = NUM2ULONG(argv[2]);
    rectangle.height = NUM2ULONG(argv[3]);

    exception = AcquireExceptionInfo();

    // Swap in color for the duration of this call.
    old_color = image->background_color;
    image->background_color = color;
    GVL_STRUCT_TYPE(SpliceImage) args = { image, &rectangle, exception };
    new_image = (Image *)CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SpliceImage), &args);
    image->background_color = old_color;

    rm_check_exception(exception, new_image, DestroyOnError);
    DestroyExceptionInfo(exception);

    return rm_image_new(new_image);
}