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

colors to case-insensitive and height and width input #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 11 additions & 5 deletions src/silpa/modules/render/render.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ def set_request(self,request):
self.font_size = self.request.get('font_size')
self.color = self.request.get('color')
self.file_type = self.request.get('file_type')

self.width = self.request.get('width')
self.height = self.request.get('height')

def set_start_response(self,start_response):
self.start_response = start_response

Expand All @@ -57,12 +59,16 @@ def get_response(self):
if self.file_type==None:
self.file_type = "png"
if self.font==None:
self.font = "Serif"
self.font = "Serif"
if self.font_size==None:
self.font_size = 12
self.font_size = 12
if self.color==None:
self.color = "Black"
image_url = self.render_text(self.text, self.file_type, 0, 0 ,self.color, self.font, self.font_size)
self.color = "Black"
if self.width==None:
self.width = 0
if self.height==None:
self.height = 0
image_url = self.render_text(self.text, self.file_type, self.width, self.height ,self.color, self.font, self.font_size)
self.response.response_code = "303 see other"
self.response.header = [('Location', image_url)]
if self.wiki_url != None:
Expand Down
18 changes: 9 additions & 9 deletions src/silpa/modules/render/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ def __init__ (self,red, green, blue, alpha=1.0):
self.blue = blue
self.alpha = alpha
__colors = {
"Black": Color(0,0,0),
"Blue": Color(0,0,1),
"Red": Color(1,0,0),
"Green": Color(0,1,0),
"Yellow": Color(1,1,0)
"black": Color(0,0,0),
"blue": Color(0,0,1),
"red": Color(1,0,0),
"green": Color(0,1,0),
"yellow": Color(1,1,0)
}

def hex_to_rgb(hex_value):
hex_value = hex_value.lstrip('#')
hex_len = len(hex_value)
if hex_len != 6 and hex_len != 8:
return __colors.get("Black")
return __colors.get("black")
else:
r, g, b = hex_value[:2], hex_value[2:4], hex_value[4:6]
if hex_len == 8:
Expand All @@ -49,11 +49,11 @@ def hex_to_rgb(hex_value):
r, g, b, a = [int(n, 16) for n in (r, g, b, a)]
return Color(round(float(r)/255, 2),round(float(g)/255, 2),round(float(b)/255, 2), round(float(a)/255, 2))
except:
return __colors.get("Black")
return __colors.get("black")

def get_color(name="Black"):
def get_color(name="black"):
if name.startswith('#'):
return hex_to_rgb(name)
else:
return __colors.get(name,__colors.get("Black"))
return __colors.get(name.lower(),__colors.get("black"))