Exemple #1
0
 /**
  * Returns an appropiate foreground color based on the brightness.
  *
  * @param Color|string $backgroundColor Color object or hex string. May include a leading '#'.
  *
  * @return string
  */
 public function textColorForBackground($backgroundColor)
 {
     if (!$backgroundColor instanceof Color) {
         $backgroundColor = Color::fromHex($backgroundColor);
     }
     if ($backgroundColor->getBrightness() < 0.65) {
         return new Color(255, 255, 255);
     }
     return new Color(0, 0, 0);
 }
Exemple #2
0
 /**
  * @param string $path
  * @param float  $score
  *
  * @return string
  */
 public function getScoreColor($path, $score)
 {
     $white = new Color(255, 255, 255);
     if ($score <= 3) {
         $green = Color::fromHex('71EF71');
         return $green->blendTo($white, ($score - 1) / 2);
     }
     if ($score <= 6) {
         return $white;
     }
     // Score after 6 to highest fades from white to red.
     $worst = $this->bounds->max($path) / $this->bounds->min($path);
     $red = Color::fromHex('FB4E4E');
     return $white->blendTo($red, $score / $worst);
 }