Method: Magick::Image#opaque

Defined in:
ext/RMagick/rmimage.c

#opaque(target, fill) ⇒ Object

Change any pixel that matches target with the color defined by fill.

Ruby usage:

- @verbatim Image#opaque(target-color-name, fill-color-name) @endverbatim
- @verbatim Image#opaque(target-pixel, fill-pixel) @endverbatim

Notes:

- By default a pixel must match the specified target color exactly.
- Use Image_fuzz_eq to set the amount of tolerance acceptable to consider
  two colors as the same.

Parameters:

  • self

    this object

  • target

    either the color name or the pixel

  • fill

    the color for filling

See Also:

  • Image_fuzz_eq

9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
# File 'ext/RMagick/rmimage.c', line 9348

VALUE
Image_opaque(VALUE self, VALUE target, VALUE fill)
{
    Image *image, *new_image;
    MagickPixelPacket target_pp;
    MagickPixelPacket fill_pp;
    MagickBooleanType okay;

    image = rm_check_destroyed(self);
    new_image = rm_clone_image(image);

    // Allow color name or Pixel
    Color_to_MagickPixelPacket(image, &target_pp, target);
    Color_to_MagickPixelPacket(image, &fill_pp, fill);

#if defined(HAVE_OPAQUEPAINTIMAGECHANNEL)
    okay = OpaquePaintImageChannel(new_image, DefaultChannels, &target_pp, &fill_pp, MagickFalse);
#else
    okay =  PaintOpaqueImageChannel(new_image, DefaultChannels, &target_pp, &fill_pp);
#endif
    rm_check_image_exception(new_image, DestroyOnError);

    if (!okay)
    {
        // Force exception
        DestroyImage(new_image);
        rm_ensure_result(NULL);
    }

    return rm_image_new(new_image);
}