ericpugh / dub-color
1.0.0
2017-01-07 17:22 UTC
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2022-01-18 17:04:43 UTC
README
查找(HEX)颜色的英文名称。名称由以下颜色调色板之一提供,或可以扩展以使用自定义调色板
示例用法
<?php use ericpugh\DubColor\Palette\Css4; use ericpugh\DubColor\ColorDubber; use ericpugh\DubColor\Color; // Create instance of DubColor and set color palette to use. $palette = Css4::getColors(); $dubber = new ColorDubber($palette); $total_num_colors = $dubber->countColorPalette(); // An example hex color. $example_hex = '#83F600'; $example_color = new Color($dubber::fromHexToInt($example_hex)); // Finds the closest HEX color in the current palette. $closest = $dubber->closestColor($example_color); // Finds the name "lawngreen". $name = $dubber->getColorName($closest); // Output results. $label = sprintf('<span>Found 1 in %d colors</span>', $total_num_colors); $color_span = sprintf('<span style="background-color:%s">Name: %s</span>', $closest, $name); echo $label . $color_span; ?>