Пример #1
0
 public function testLightenWithDefaultAdjustment()
 {
     $expected = array("336699" => "4080bf", "913399" => "b540bf");
     foreach ($expected as $original => $darker) {
         $color = new Color($original);
         $this->assertEquals($darker, $color->lighten(), "Incorrect lighter color returned.");
     }
 }
Пример #2
0
<?php

include "../src/color.php";
use phpColors\Color;
// Use different colors to test
$myBlue = new Color("#336699");
$myBlack = new Color("#333");
$myPurple = new Color("#913399");
// ************** No Need to Change Below **********************
?>
<style> 
	.block{
		height:100px;
		width:200px;
		font-size:20px;
		text-align:center;
		padding-top:100px;
		display:block;
		margin:0px;
		float:left;
	}
	.clear{ clear:both; }
	
	.testDiv{
		<?php 
echo $myBlue->getCssGradient();
?>
		color: <?php 
echo $myBlue->isDark() ? "#EEE" : "#333";
?>
;
Пример #3
0
function calculate_taggings($colors)
{
    $target_colors = array($colors[4], $colors[5]);
    $tagging_tag_names = array();
    foreach ($target_colors as $color) {
        $color_obj = new Color("#" . $color);
        $hsl = $color_obj->getHsl();
        if ($hsl["L"] > 0.9) {
            $tagging_tag_names[] = "white";
            continue;
        } else {
            if ($hsl["L"] < 0.1) {
                $tagging_tag_names[] = "black";
                continue;
            } else {
                if ($hsl["S"] < 0.1) {
                    $tagging_tag_names[] = "gray";
                    continue;
                }
            }
        }
        $hue = (int) (($hsl["H"] + 22.5) / 45.0);
        if ($hue == 8) {
            $hue = 0;
        }
        switch ($hue) {
            case 0:
                $tagging_tag_names[] = "red";
                break;
            case 1:
                $tagging_tag_names[] = "yellow";
                break;
            case 2:
                $tagging_tag_names[] = "yellow_green";
                break;
            case 3:
                $tagging_tag_names[] = "green";
                break;
            case 4:
                $tagging_tag_names[] = "aqua_blue";
                break;
            case 5:
                $tagging_tag_names[] = "blue";
                break;
            case 6:
                $tagging_tag_names[] = "violet";
                break;
            case 7:
                $tagging_tag_names[] = "purple";
                break;
        }
        if ($hsl["S"] > 2.0 / 3.0) {
            $tagging_tag_names[] = "high_saturation";
        } else {
            if ($hsl["S"] < 1.0 / 3.0) {
                $tagging_tag_names[] = "low_saturation";
            } else {
                $tagging_tag_names[] = "normal_saturation";
            }
        }
        if ($hsl["L"] > 2.0 / 3.0) {
            $tagging_tag_names[] = "high_lightness";
        } else {
            if ($hsl["L"] < 1.0 / 3.0) {
                $tagging_tag_names[] = "low_lightness";
            } else {
                $tagging_tag_names[] = "normal_lightness";
            }
        }
    }
    $tagging_tag_names = array_unique($tagging_tag_names);
    return $tagging_tag_names;
}