Method: Magick::Image#displace

Defined in:
ext/RMagick/rmimage.cpp

#displace(displacement_map, x_amp, y_amp = x_amp, gravity = Magick::NorthWestGravity, x_offset = 0, y_offset = 0) ⇒ Magick::Image

Uses displacement_map to move color from img to the output image. This method corresponds to the -displace option of ImageMagick’s composite command.

NorthWest corner by default.

Parameters:

  • displacement_map (Magick::Image, Magick::ImageList)

    The source image for the composite operation. Either an imagelist or an image. If an imagelist, uses the current image.

  • x_amp (Numeric)

    The maximum displacement on the x-axis.

  • y_amp (Numeric) (defaults to: x_amp)

    The maximum displacement on the y-axis.

  • gravity (Magick::GravityType) (defaults to: Magick::NorthWestGravity)

    the gravity for offset. the offsets are measured from the

  • x_offset (Numeric) (defaults to: 0)

    The offset that measured from the left-hand side of the target image.

  • y_offset (Numeric) (defaults to: 0)

    The offset that measured from the top of the target image.

Returns:



5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
# File 'ext/RMagick/rmimage.cpp', line 5605

VALUE
Image_displace(int argc, VALUE *argv, VALUE self)
{
    Image *image, *displacement_map;
    VALUE dmap;
    double x_amplitude = 0.0, y_amplitude = 0.0;
    long x_offset = 0L, y_offset = 0L;

    image = rm_check_destroyed(self);

    if (argc < 2)
    {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 2 to 6)", argc);
    }

    dmap = rm_cur_image(argv[0]);
    displacement_map = rm_check_destroyed(dmap);

    if (argc > 3)
    {
        get_composite_offsets(argc-3, &argv[3], image, displacement_map, &x_offset, &y_offset);
        // There must be 3 arguments left
        argc = 3;
    }

    switch (argc)
    {
        case 3:
            y_amplitude = NUM2DBL(argv[2]);
            x_amplitude = NUM2DBL(argv[1]);
            break;
        case 2:
            x_amplitude = NUM2DBL(argv[1]);
            y_amplitude = x_amplitude;
            break;
    }

    RB_GC_GUARD(dmap);

    return special_composite(image, displacement_map, x_amplitude, y_amplitude,
                             x_offset, y_offset, DisplaceCompositeOp);
}