-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathunit_conversion.py
More file actions
62 lines (42 loc) · 1.69 KB
/
unit_conversion.py
File metadata and controls
62 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
def convert(value, start_unit, des_unit, dpi) -> float:
if start_unit == 'mm' and des_unit == 'pt':
value = value / 0.352777778
elif start_unit == 'px' and des_unit == 'pt':
value = value
elif start_unit == 'pt' and des_unit == 'mm':
value = value * 0.352777778
elif start_unit == 'px' and des_unit == 'mm':
value = value * 25.4 / dpi
elif start_unit == 'mm' and des_unit == 'px':
value = dpi * value / 25.4
elif start_unit == 'pt' and des_unit == 'px':
value = value
elif start_unit == 'in' and des_unit == 'pt':
value = value * 25.4 / 0.352777778
elif start_unit == 'in' and des_unit == 'mm':
value = value * 25.4
elif start_unit == 'in' and des_unit == 'px':
value = dpi * value
elif start_unit == 'pt' and des_unit == 'in':
value = value * 0.352777778 / 25.4
elif start_unit == 'mm' and des_unit == 'in':
value = value / 25.4
elif start_unit == 'px' and des_unit == 'in':
value = dpi / value
elif start_unit == 'cm' and des_unit == 'mm':
value = value * 10
elif start_unit == 'cm' and des_unit == 'in':
value = value / 2.54
elif start_unit == 'cm' and des_unit == 'pt':
value = value / 0.0352777778
elif start_unit == 'cm' and des_unit == 'px':
value = dpi * value / 2.54
elif start_unit == 'px' and des_unit == 'cm':
value = value * 2.54 / dpi
elif start_unit == 'mm' and des_unit == 'cm':
value = value / 10
elif start_unit == 'in' and des_unit == 'cm':
value = value * 2.54
elif start_unit == 'pt' and des_unit == 'cm':
value = value * 0.0352777778
return value