private function extractHexColor(Photo $photo, $temporary_location) { $palette = Palette::fromFilename($temporary_location); $extractor = new ColorExtractor($palette); $colors = $extractor->extract(); return $colors[0]; }
public function createStyles($data) { //if data is an array (passed through from form), then access appropriate variable if (is_array($data)) { $this->imageURL = !empty($data['imageurl']) ? $data['imageurl'] : null; } else { $this->imageURL = $data; } //test if image size is too big $this->imageSize = getimagesize($this->imageURL); if ($this->imageSize[0] > 1000 || $this->imageSize[1] > 1000) { $this->error = 'Image is too large. Please try a smaller image.'; } else { //extract 4 colors $palette = Palette::fromFilename($this->imageURL); $extractor = new ColorExtractor($palette); $colors = $extractor->extract(4); $bwResult = []; foreach ($colors as $color) { $hexValueColor = Color::fromIntToHex($color); $this->colorsResult[] = $hexValueColor; //test each color to see if white or black will show up better for font //credit: https://24ways.org/2010/calculating-color-contrast/ if (hexdec($hexValueColor) > 0xffffff / 2) { $bwResult[] = '#000'; } else { $bwResult[] = '#FFF'; } } $this->cssResult = '#custom-bootstrap-menu.navbar-default .navbar-brand { color: ' . $bwResult[0] . '; } #custom-bootstrap-menu.navbar-default { font-size: 14px; background-color: ' . $this->colorsResult[0] . '; border-width: 1px; border-radius: 4px; } #custom-bootstrap-menu.navbar-default .navbar-nav>li>a { color: ' . $bwResult[0] . '; background-color: ' . $this->colorsResult[0] . '; } #custom-bootstrap-menu.navbar-default .navbar-nav>li>a:hover, #custom-bootstrap-menu.navbar-default .navbar-nav>li>a:focus { color: ' . $bwResult[1] . '; background-color: ' . $this->colorsResult[1] . '; } #custom-bootstrap-menu.navbar-default .navbar-nav>.active>a, #custom-bootstrap-menu.navbar-default .navbar-nav>.active>a:hover, #custom-bootstrap-menu.navbar-default .navbar-nav>.active>a:focus { color: ' . $bwResult[2] . '; background-color: ' . $this->colorsResult[2] . '; } #custom-bootstrap-menu.navbar-default .navbar-toggle { border-color: .' . $this->colorsResult[2] . '; } #custom-bootstrap-menu.navbar-default .navbar-toggle:hover, #custom-bootstrap-menu.navbar-default .navbar-toggle:focus { background-color: ' . $this->colorsResult[2] . '; } #custom-bootstrap-menu.navbar-default .navbar-toggle .icon-bar { background-color: ' . $this->colorsResult[2] . '; } #custom-bootstrap-menu.navbar-default .navbar-toggle:hover .icon-bar, #custom-bootstrap-menu.navbar-default .navbar-toggle:focus .icon-bar { background-color: ' . $this->colorsResult[0] . '; }'; } }