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

Py3 fixes to lib/color_compliment.py #220

Merged
merged 4 commits into from
Dec 26, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions lib/color_compliment.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
#! /usr/bin/env python

from colortrans import *
from colorsys import hls_to_rgb, rgb_to_hls
from md5 import md5
from sys import argv
# md5 deprecated since Python 2.5
try:
from md5 import md5
except ImportError:
from hashlib import md5
import sys

# Original, non-relative import errors on Python3
from .colortrans import *

py3 = sys.version_info[0] == 3


def getOppositeColor(r,g,b):
Expand All @@ -27,6 +34,10 @@ def getOppositeColor(r,g,b):
return tuple([ int(x) for x in opp])

def stringToHashToColorAndOpposite(string):
# Python3: Unicode string must be encoded before digest
# Python2.7: works either way, but check in case breaks earlier py2
if py3:
string = string.encode('utf-8')
string = md5(string).hexdigest()[:6] # get a random color
color1 = rgbstring2tuple(string)
color2 = getOppositeColor(*color1)
Expand Down