Skip to contents

Converts RGBA to RGB (helper function)

Usage

rgba_to_rgb(colour_rgba, background_colour = "#ffffff", ...)

Arguments

colour_rgba

A vector of length 4: c(red value, green value, blue value, alpha). All colour values must be between 0 and 255. Alpha must be between 0 and 1.

background_colour

Defaults to white. Users can specify a different colour to get the hex code for their original colour blended with a specified background colour. background_colour must either be a recognised colour name (e.g. "white"), a hex colour code (e.g. "#ffffff") or vector of length 3 (red value, green value, blue value), with all values between 0 and 255. The default value is white ("#ffffff").

...

US spellings of the arguments above: color_rgba and background_color. Other argument names give an error.

Value

A matrix of red, green and blue values

Examples

rgba_to_rgb(c(52, 46, 39, 0.8))
#>       [,1]
#> red   92.6
#> green 87.8
#> blue  82.2

rgba_to_rgb(c(52, 46, 39, 0.8), "blue")
#>       [,1]
#> red   41.6
#> green 36.8
#> blue  82.2

rgba_to_rgb(c(52, 46, 39, 0.8), "#032cfc")
#>       [,1]
#> red   42.2
#> green 45.6
#> blue  81.6