-
Notifications
You must be signed in to change notification settings - Fork 1
/
helper.php
38 lines (32 loc) · 1.04 KB
/
helper.php
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
<?php
/**
* @package J51_ImageHover
* @copyright Copyright (C) 2009 - 2017 Joomla51. All rights reserved.
* @license GPL v3.0 or later http://www.gnu.org/licenses/gpl-3.0.html
*/
// no direct access
defined('_JEXEC') or die('Restricted access');
class modJ51ImageHover
{
public function adjustBrightness($hex, $steps)
{
// Steps should be between -255 and 255. Negative = darker, positive = lighter
$steps = max(-255, min(255, $steps));
// Normalize into a six character long hex string
$hex = str_replace('#', '', $hex);
if (strlen($hex) == 3)
{
$hex = str_repeat(substr($hex, 0, 1), 2) . str_repeat(substr($hex, 1, 1), 2) . str_repeat(substr($hex, 2, 1), 2);
}
// Split into three parts: R, G and B
$color_parts = str_split($hex, 2);
$return = '#';
foreach ($color_parts as $color)
{
$color = hexdec($color); // Convert to decimal
$color = max(0, min(255, $color + $steps)); // Adjust color
$return .= str_pad(dechex($color), 2, '0', STR_PAD_LEFT); // Make two char hex code
}
return $return;
}
}