Method: Magick::Image#alpha

Defined in:
ext/RMagick/rmimage.cpp

#alphaBoolean #alpha(value) ⇒ Magick::AlphaChannelOption

Get/Set alpha channel.

  • Replaces #matte=, #alpha=

  • Originally there was an alpha attribute getter and setter. These are replaced with alpha? and alpha(type). We still define (but don’t document) alpha=. For backward compatibility, if this method is called without an argument, make it act like the old alpha getter and return true if the matte channel is active, false otherwise.

Overloads:

  • #alphaBoolean

    Returns true if the alpha channel will be used, false otherwise. This calling is same as #alpha?.

    Returns:

    • (Boolean)

      true or false

    See Also:

  • #alpha(value) ⇒ Magick::AlphaChannelOption

    Activates, deactivates, resets, or sets the alpha channel.

    Parameters:

    • value (Magick::AlphaChannelOption)

      An AlphaChannelOption value

    Returns:

    • (Magick::AlphaChannelOption)

      the given value



874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
# File 'ext/RMagick/rmimage.cpp', line 874

VALUE
Image_alpha(int argc, VALUE *argv, VALUE self)
{
    Image *image;
    AlphaChannelOption alpha;
#if defined(IMAGEMAGICK_7)
    ExceptionInfo *exception;
#endif


    // For backward compatibility, make alpha() act like alpha?
    if (argc == 0)
    {
        return Image_alpha_q(self);
    }
    else if (argc > 1)
    {
        rb_raise(rb_eArgError, "wrong number of arguments (%d for 1)", argc);
    }


    image = rm_check_frozen(self);
    VALUE_TO_ENUM(argv[0], alpha, AlphaChannelOption);

#if defined(IMAGEMAGICK_7)
    exception = AcquireExceptionInfo();
    GVL_STRUCT_TYPE(SetImageAlphaChannel) args = { image, alpha, exception };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageAlphaChannel), &args);
    CHECK_EXCEPTION();
    DestroyExceptionInfo(exception);
#else
    GVL_STRUCT_TYPE(SetImageAlphaChannel) args = { image, alpha };
    CALL_FUNC_WITHOUT_GVL(GVL_FUNC(SetImageAlphaChannel), &args);
    rm_check_image_exception(image, RetainOnError);
#endif

    return argv[0];
}