PW-567 add the old canvas formula
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user