Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept and return integer RGB values? #36

Open
tony opened this issue Aug 16, 2017 · 2 comments
Open

Accept and return integer RGB values? #36

tony opened this issue Aug 16, 2017 · 2 comments

Comments

@tony
Copy link

tony commented Aug 16, 2017

Is there a chance integer RGB values can be accepted? It makes compatibility with PIL's color signatures more streamlined.

@giswqs
Copy link

giswqs commented Apr 14, 2020

I second this. It would be nice to support integer RGB values from 0 to 255.

@giswqs
Copy link

giswqs commented Apr 14, 2020

I wrote a function for accepting integer RGB values. It is not perfect, but it gets the job done for me.

from colour import Color

def check_color(in_color):

    out_color = ''
    if isinstance(in_color, tuple) and len(in_color) == 3:
        if all(isinstance(item, int) for item in in_color):
            rescaled_color = [x / 255.0 for x in in_color]
            out_color = Color(rgb=tuple(rescaled_color))
            return out_color
        else: 
            print('RGB color must be a tuple with three integer values ranging from 0 to 255.')
            return
    else:
        try:
            out_color = Color(in_color)
            return out_color
        except Exception as e:
            print('The provided color is invalid.')
            print(e)
            return

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants