Method: Magick::Image#watermark

Defined in:
ext/RMagick/rmimage.cpp

#watermark(mark, brightness = 1.0, saturation = 1.0, x_off = 0, y_off = 0) ⇒ Magick::Image #watermark(mark, brightness, saturation, gravity, x_off = 0, y_off = 0) ⇒ Magick::Image

Composites a watermark image on the target image using the Modulate composite operator. This composite operation operates in the HSL colorspace and combines part of the lightness, part of the saturation, and all of the hue of each pixel in the watermark with the corresponding pixel in the target image

Overloads:

  • #watermark(mark, brightness = 1.0, saturation = 1.0, x_off = 0, y_off = 0) ⇒ Magick::Image

    Parameters:

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

      Either an imagelist or an image. If an imagelist, uses the current image.

    • brightness (Numeric, String) (defaults to: 1.0)

      The fraction of the lightness component of the watermark pixels to be composited onto the target image. Must be a non-negative number or a string in the form “NN%”. If lightness is a number it is interpreted as a percentage. Both 0.25 and “25%” mean 25%. The default is 100%.

    • saturation (Numeric, String) (defaults to: 1.0)

      The fraction of the saturation component of the watermark pixels to be composited onto the target image. Must be a non-negative number or a string in the form “NN%”. If lightness is a number it is interpreted as a percentage. Both 0.25 and “25%” mean 25%. The default is 100%.

    • x_off (Numeric) (defaults to: 0)

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

    • y_off (Numeri) (defaults to: 0)

      The offset of the watermark, measured from the top of the target image.

  • #watermark(mark, brightness, saturation, gravity, x_off = 0, y_off = 0) ⇒ Magick::Image

    Parameters:

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

      Either an imagelist or an image. If an imagelist, uses the current image.

    • brightness (Numeric, String)

      The fraction of the lightness component of the watermark pixels to be composited onto the target image. Must be a non-negative number or a string in the form “NN%”. If lightness is a number it is interpreted as a percentage. Both 0.25 and “25%” mean 25%. The default is 100%.

    • saturation (Numeric, String)

      The fraction of the saturation component of the watermark pixels to be composited onto the target image. Must be a non-negative number or a string in the form “NN%”. If lightness is a number it is interpreted as a percentage. Both 0.25 and “25%” mean 25%. The default is 100%.

    • gravity (Magick::GravityType)

      the gravity for offset. the offsets are measured from the NorthWest corner by default.

    • x_off (Numeric) (defaults to: 0)

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

    • y_off (Numeri) (defaults to: 0)

      The offset of the watermark, measured from the top of the target image.

Returns:



15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
# File 'ext/RMagick/rmimage.cpp', line 15508

VALUE
Image_watermark(int argc, VALUE *argv, VALUE self)
{
    Image *image, *overlay, *new_image;
    double src_percent = 100.0, dst_percent = 100.0;
    long x_offset = 0L, y_offset = 0L;
    char geometry[20];
    VALUE ovly;
#if defined(IMAGEMAGICK_7)
    ExceptionInfo *exception;
#endif

    image = rm_check_destroyed(self);

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

    ovly = rm_cur_image(argv[0]);
    overlay = rm_check_destroyed(ovly);

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

    switch (argc)
    {
        case 3:
            dst_percent = rm_percentage(argv[2], 1.0) * 100.0;
        case 2:
            src_percent = rm_percentage(argv[1], 1.0) * 100.0;
        case 1:
            break;
        default:
            rb_raise(rb_eArgError, "wrong number of arguments (%d for 1 to 6)", argc);
            break;
    }

    blend_geometry(geometry, sizeof(geometry), src_percent, dst_percent);
    CloneString(&overlay->geometry, geometry);
    SetImageArtifact(overlay, "compose:args", geometry);

    new_image = rm_clone_image(image);
#if defined(IMAGEMAGICK_7)
    exception = AcquireExceptionInfo();
    GVL_STRUCT_TYPE(CompositeImage) args = { new_image, overlay, ModulateCompositeOp, MagickTrue, x_offset, y_offset, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImage), &args);
    rm_check_exception(exception, new_image, DestroyOnError);
    DestroyExceptionInfo(exception);
#else
    GVL_STRUCT_TYPE(CompositeImage) args = { new_image, ModulateCompositeOp, overlay, x_offset, y_offset };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(CompositeImage), &args);

    rm_check_image_exception(new_image, DestroyOnError);
#endif

    RB_GC_GUARD(ovly);

    return rm_image_new(new_image);
}