-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelper.php
More file actions
68 lines (60 loc) · 1.71 KB
/
Copy pathHelper.php
File metadata and controls
68 lines (60 loc) · 1.71 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
<?php
namespace x000000\StorageManager;
class Helper
{
/**
* Serialize $transforms to a single string
* @param Transforms\AbstractTransform[] $transforms List of transforms
* @return string Serialized string
*/
public static function serializeTransforms($transforms)
{
if (!is_array($transforms)) {
return '';
}
$tr = array();
foreach ($transforms as $key => $value) {
$tr[] = (string) $value;
}
return empty($tr) ? '' : '&' . implode('&', $tr);
}
/**
* Returns serialized $value with null check
* @param mixed $value Value to be serialized
* @return string Serialized $value
*/
public static function nullSerialize($value)
{
return $value === null ? 'null' : (string) $value;
}
/**
* Convert percent value to absolute value
* @param string $percent Percent value with trailed '%'
* @param number $maxValue 100% value for a reference
* @return number Return a percent value based on $percent of $maxValue.
* If $percent isn't trailed by '%', then $percent will be returned without changes.
*/
public static function percentValue($percent, $maxValue)
{
return substr($percent, -1) == '%'
? rtrim($percent, ' %') * .01 * $maxValue
: $percent;
}
/**
* Modifies $width or $height (if one of them is empty) based on $box ratio.
* @param number|null $width Desired width
* @param number|null $height Desired height
* @param \Imagine\Image\BoxInterface $box Original box for a reference
*/
public static function scaleSize(&$width, &$height, \Imagine\Image\BoxInterface $box)
{
if (!$width || !$height) {
$r = $box->getWidth() / $box->getHeight();
if ($width) {
$height = floor($width / $r);
} else {
$width = floor($height * $r);
}
}
}
}