PW-567 add the old canvas formula

This commit is contained in:
Martin
2016-10-31 17:57:11 +01:00
parent cbee61b564
commit bf9fc3ae5a
10 changed files with 352 additions and 35 deletions
+52
View File
@@ -0,0 +1,52 @@
# coding=UTF-8
CANVAS = {
'max_long_side': 500,
'min_long_side': 20,
'max_short_side': 150,
'min_short_side': 20
}
CANVAS_FRAME = {
'max_long_side': 150,
'min_long_side': 40,
'max_short_side': 150,
'min_short_side': 40,
}
def calculate_canvas_frame_limits(width, height):
if width > height:
width = min(width, CANVAS_FRAME.get('max_long_side'))
width = max(width, CANVAS_FRAME.get('min_long_side'))
height = min(height, CANVAS_FRAME.get('max_short_side'))
height = max(height, CANVAS_FRAME.get('min_short_side'))
else:
height = min(height, CANVAS_FRAME.get('max_long_side'))
height = max(height, CANVAS_FRAME.get('min_long_side'))
width = min(width, CANVAS_FRAME.get('max_short_side'))
width = max(width, CANVAS_FRAME.get('min_short_side'))
# round to nearest 10
width = round(width, -1)
height = round(height, -1)
return width, height
def calculate_canvas_limits(width, height, framed=False):
if framed:
return calculate_canvas_frame_limits(width, height)
if width > height:
width = min(width, CANVAS.get('max_long_side'))
width = max(width, CANVAS.get('min_long_side'))
height = min(height, CANVAS.get('max_short_side'))
height = max(height, CANVAS.get('min_short_side'))
else:
height = min(height, CANVAS.get('max_long_side'))
height = max(height, CANVAS.get('min_long_side'))
width = min(width, CANVAS.get('max_short_side'))
width = max(width, CANVAS.get('min_short_side'))
return width, height