Fix some pylint issues and issue with single digit colors

This commit is contained in:
Oliver Falk
2020-05-06 13:07:19 +02:00
parent 30991b4b57
commit 0262ad850f

View File

@@ -35,7 +35,7 @@ def openid_variations(openid):
var3 = var2[0:-1] var3 = var2[0:-1]
return (openid, var1, var2, var3) return (openid, var1, var2, var3)
def mm_ng(hash, size=80, add_red=0, add_green=0, add_blue=0): def mm_ng(idhash, size=80, add_red=0, add_green=0, add_blue=0): #pylint: disable=too-many-locals
''' '''
Return an MM (mystery man) image, based on a given hash Return an MM (mystery man) image, based on a given hash
add some red, green or blue, if specified add some red, green or blue, if specified
@@ -43,7 +43,8 @@ def mm_ng(hash, size=80, add_red=0, add_green=0, add_blue=0):
# Make sure the lightest bg color we paint is e0, else # Make sure the lightest bg color we paint is e0, else
# we do not see the MM any more # we do not see the MM any more
if hash[0] == 'f': hash = 'e0' if idhash[0] == 'f':
idhash = 'e0'
# How large is the circle? # How large is the circle?
circlesize = size*0.6 circlesize = size*0.6
@@ -56,21 +57,30 @@ def mm_ng(hash, size=80, add_red=0, add_green=0, add_blue=0):
# All are the same, based on the input hash # All are the same, based on the input hash
# this should always result in a "gray-ish" background # this should always result in a "gray-ish" background
red = hash[0:2] red = idhash[0:2]
green = hash[0:2] green = idhash[0:2]
blue = hash[0:2] blue = idhash[0:2]
# Add some red (i/a) and make sure it's not over 255 # Add some red (i/a) and make sure it's not over 255
red = hex(int(red, 16)+add_red).replace('0x', '') red = hex(int(red, 16)+add_red).replace('0x', '')
if int(red, 16)>255: red='ff' if int(red, 16) > 255:
red = 'ff'
if len(red) == 1:
red = '0%s' % red
# Add some green (i/a) and make sure it's not over 255 # Add some green (i/a) and make sure it's not over 255
green = hex(int(green, 16)+add_green).replace('0x', '') green = hex(int(green, 16)+add_green).replace('0x', '')
if int(green, 16)>255: green='ff' if int(green, 16) > 255:
green = 'ff'
if len(green) == 1:
green = '0%s' % green
# Add some blue (i/a) and make sure it's not over 255 # Add some blue (i/a) and make sure it's not over 255
blue = hex(int(blue, 16)+add_blue).replace('0x', '') blue = hex(int(blue, 16)+add_blue).replace('0x', '')
if int(blue, 16)>255: blue='ff' if int(blue, 16) > 255:
blue = 'ff'
if len(blue) == 1:
blue = '0%s' % blue
# Assemable the bg color "string" in webnotation. Eg. '#d3d3d3' # Assemable the bg color "string" in webnotation. Eg. '#d3d3d3'
bg_color = '#' + red + green + blue bg_color = '#' + red + green + blue
@@ -80,12 +90,16 @@ def mm_ng(hash, size=80, add_red=0, add_green=0, add_blue=0):
draw = ImageDraw.Draw(image) draw = ImageDraw.Draw(image)
# Draw background # Draw background
draw.rectangle(((0,0), (size, size)), fill=bg_color) draw.rectangle(((0, 0), (size, size)), fill=bg_color)
# Draw MMs head # Draw MMs head
draw.ellipse((start_x, start_y, end_x, end_y), fill='white') draw.ellipse((start_x, start_y, end_x, end_y), fill='white')
# Draw MMs 'body' # Draw MMs 'body'
draw.polygon(((start_x+circlesize/2, size/2.5), (size*0.15, size), (size-size*0.15, size)), fill='white') draw.polygon((
(start_x+circlesize/2, size/2.5),
(size*0.15, size),
(size-size*0.15, size)),
fill='white')
return image return image