跳转至

maliang.color.convert

字数 9 个   阅读时间不到 1 分钟   访问量

源代码:maliang/color/convert.py

Convert a format of color to another format.

  • RGB: tuple, (Red, Green, Blue)
  • HSL: tuple, (Hue, Saturation, Lightness)
  • RGBA: tuple, (Red, Green, Blue, Alpha)
  • HEX: hexadecimal, such as ‘#ABCDEF’ or ‘#12345678’
  • NAME: string, such as ‘royalblue’

函数:

  • rgb_to_hex

    Convert a RGB code to a hexadecimal code.

  • hex_to_rgb

    Convert a hexadecimal code to a RGB code.

  • rgba_to_hex

    Convert a RGBA code to a hexadecimal code.

  • hex_to_rgba

    Convert a hexadecimal code to a RGBA code.

  • hsl_to_rgb

    Convert a HSL code to a RGB code.

  • rgb_to_hsl

    Convert a RGB code to a HSL code.

  • hsl_to_hex

    Convert a HSL code to a hexadecimal code.

  • hex_to_hsl

    Convert a hexadecimal code to a HSL code.

  • name_to_rgb

    Convert a color name to a RGB code.

  • rgb_to_name

    Convert a RGB code to a color name.

  • name_to_hex

    Convert a color name to a hexadecimal code.

  • hex_to_name

    Convert a hexadecimal code to a color name.

  • fix_hex_length

    Fix the length of a hexadecimal code.

  • str_to_rgb

    Convert a color name or a hexadecimal code to a RGB code.

rgb_to_hex

rgb_to_hex(value: tuple[int, int, int]) -> str

Convert a RGB code to a hexadecimal code.

  • value: a RGB code

hex_to_rgb

hex_to_rgb(value: str) -> tuple[int, int, int]

Convert a hexadecimal code to a RGB code.

  • value: a hexadecimal code

rgba_to_hex

rgba_to_hex(value: tuple[int, int, int, float]) -> str

Convert a RGBA code to a hexadecimal code.

  • value: a RGBA code

hex_to_rgba

hex_to_rgba(value: str) -> tuple[int, int, int, float]

Convert a hexadecimal code to a RGBA code.

  • value: a hexadecimal code

rgb_to_rgba

rgb_to_rgba(value: tuple[int, int, int]) -> tuple[int, int, int, float]

Convert a RGB code to a RGBA code.

  • value: a RGB code

rgba_to_rgb

rgba_to_rgb(
    value: tuple[int, int, int, float], /, *, refer: tuple[int, int, int]
) -> tuple[int, int, int]

Convert a RGBA code to a RGB code.

  • value: a RGBA code
  • refer: a RGB code

hsl_to_rgb

hsl_to_rgb(value: tuple[float, float, float]) -> tuple[int, int, int]

Convert a HSL code to a RGB code.

  • value: a HSL code

rgb_to_hsl

rgb_to_hsl(value: tuple[int, int, int]) -> tuple[float, float, float]

Convert a RGB code to a HSL code.

  • value: a RGB code

hsl_to_hex

hsl_to_hex(value: tuple[float, float, float]) -> str

Convert a HSL code to a hexadecimal code.

  • value: a HSL code

hex_to_hsl

hex_to_hsl(value: str) -> tuple[float, float, float]

Convert a hexadecimal code to a HSL code.

  • value: a hexadecimal code

name_to_rgb

name_to_rgb(value: str) -> tuple[int, int, int]

Convert a color name to a RGB code.

  • value: a color name

rgb_to_name

rgb_to_name(value: tuple[int, int, int]) -> list[str]

Convert a RGB code to a color name.

  • value: a RGB code

name_to_hex

name_to_hex(value: str) -> str

Convert a color name to a hexadecimal code.

  • value: a color name

hex_to_name

hex_to_name(value: str) -> list[str]

Convert a hexadecimal code to a color name.

  • value: a hexadecimal code

fix_hex_length

fix_hex_length(value: str) -> str

Fix the length of a hexadecimal code.

  • value: a hexadecimal code

str_to_rgb

str_to_rgb(value: str) -> tuple[int, int, int]

Convert a color name or a hexadecimal code to a RGB code.

  • value: a color name or a hexadecimal code