-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
⬆️ Require PHP 8.0, use named parameters
- Loading branch information
1 parent
e231546
commit e9e9e5c
Showing
7 changed files
with
61 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
} | ||
}, | ||
"require": { | ||
"php": ">=7.0", | ||
"ext-gd" : ">=7.0" | ||
"php": ">=8.0", | ||
"ext-gd" : ">=8.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
<?php | ||
|
||
/** | ||
* @author Nico Verbruggen <[email protected]> | ||
* @copyright 2017 Nico Verbruggen | ||
* @link https://nicoverbruggen.be | ||
*/ | ||
|
||
namespace NicoVerbruggen\ImageGenerator\Helpers; | ||
|
||
class ColorHelper | ||
|
@@ -17,7 +11,7 @@ class ColorHelper | |
* | ||
* @return string | ||
*/ | ||
public static function randomHex() | ||
public static function randomHex(): string | ||
{ | ||
return '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); | ||
} | ||
|
@@ -30,20 +24,23 @@ public static function randomHex() | |
* | ||
* @return string | ||
*/ | ||
public static function contrastColor($hex) | ||
public static function contrastColor($hex): string | ||
{ | ||
//////////// hexColor RGB | ||
// Remove the # to avoid errors | ||
$hex = str_replace('#', '', $hex); | ||
|
||
// hexColor RGB | ||
$R1 = hexdec(substr($hex, 0, 2)); | ||
$G1 = hexdec(substr($hex, 2, 2)); | ||
$B1 = hexdec(substr($hex, 4, 2)); | ||
|
||
//////////// Black RGB | ||
$blackColor = "#000000"; | ||
// Black RGB | ||
$blackColor = "000000"; | ||
$R2BlackColor = hexdec(substr($blackColor, 0, 2)); | ||
$G2BlackColor = hexdec(substr($blackColor, 2, 2)); | ||
$B2BlackColor = hexdec(substr($blackColor, 4, 2)); | ||
|
||
//////////// Calc contrast ratio | ||
// Calc contrast ratio | ||
$L1 = 0.2126 * pow($R1 / 255, 2.2) + | ||
0.7152 * pow($G1 / 255, 2.2) + | ||
0.0722 * pow($B1 / 255, 2.2); | ||
|
@@ -52,18 +49,17 @@ public static function contrastColor($hex) | |
0.7152 * pow($G2BlackColor / 255, 2.2) + | ||
0.0722 * pow($B2BlackColor / 255, 2.2); | ||
|
||
$contrastRatio = 0; | ||
if ($L1 > $L2) { | ||
$contrastRatio = (int)(($L1 + 0.05) / ($L2 + 0.05)); | ||
} else { | ||
$contrastRatio = (int)(($L2 + 0.05) / ($L1 + 0.05)); | ||
} | ||
|
||
//////////// If contrast is more than 5, return black color | ||
// If contrast is more than 5, return black color | ||
if ($contrastRatio > 5) { | ||
return '#000'; | ||
} else { //////////// if not, return white color. | ||
} else { // if not, return white color. | ||
return '#FFF'; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters