class_mcUnityCalculator.inc.php
2.68 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* @copyright (c) 2014, netz.coop eG
*/
class mcUnityCalculator {
public static $UNITS = array(
'in' => array(
'mm' => 25.4,
'cm' => 2.54,
'in' => 1,
'pt' => 72,
'pc' => 6,
'px' => false,
)
);
/**
* transform $param_in_number $param_in_unit to $param_out_unit
*
* @param number $param_in_number
* @param string $param_in_unit
* @param string $param_out_unit
* @return number
*/
public static function to($param_in_number, $param_in_unit, $param_out_unit, $param_dpi=300){
D::li("to($param_in_number, $param_in_unit, $param_out_unit, $param_dpi=300){");
$inchNumber = mcUnityCalculator::toInch($param_in_number, $param_in_unit, $param_dpi);
$outNumber = mcUnityCalculator::inchTo($inchNumber, $param_out_unit, $param_dpi);
return $outNumber;
}
public static function calculateDpi($param_px_number, $param_number, $param_unit) {
$inch_outNumber = mcUnityCalculator::toInch($param_number, $param_unit);
$dpi = $param_px_number / $inch_outNumber;
return $dpi;
}
/**
*
* @param type $param_number - number in inch / zahl in zoll
* @param string $param_unit - mm / cm / in / pt / pc / px
* @return type
*/
private static function inchTo($param_number, $param_unit, $param_dpi=300) {
if(array_key_exists($param_unit, mcUnityCalculator::$UNITS['in'])) {
if($param_unit != 'px') {
return $param_number * mcUnityCalculator::$UNITS['in'][$param_unit];
} else {
return mcUnityCalculator::inchToPx($param_number, $param_dpi);
}
} else {
return Error::newError('falsche Einheit', '');
}
}
/**
*
* @param type $param_number - number in inch / zahl in zoll
* @param string $param_unit - mm / cm / in / pt / pc / px
* @return type
*/
private static function toInch($param_number, $param_unit, $param_dpi=300) {
if(array_key_exists($param_unit, mcUnityCalculator::$UNITS['in'])) {
if($param_unit != 'px') {
return $param_number / mcUnityCalculator::$UNITS['in'][$param_unit];
} else {
return mcUnityCalculator::pxToInch($param_number, $param_dpi);
}
} else {
return Error::newError('falsche Einheit', '');
}
}
// /**
// *
// * @param type $param_number
// * @param type $param_unit
// * @param type $param_dpi
// * @return type
// */
// public static function toPx($param_number, $param_unit, $param_dpi) {
// $inch = mcUnityCalculator::toInch($param_number, $param_unit);
// $px = mcUnityCalculator::inchToPx($inch, $param_dpi);
// return $px;
// }
private static function pxToInch($param_px, $param_dpi) {
return $param_px / $param_dpi;
}
private static function inchToPx($param_inch, $param_dpi) {
return $param_inch * $param_dpi;
}
}
?>