function rgbStringToHsl($rgbString) { $pattern = "/rgba*\\((?P<r>\\d+\\.*\\d*),(?P<g>\\d+\\.*\\d*),(?P<b>\\d+\\.*\\d*),*(?P<a>\\d*\\.*\\d*)\\)/i"; if (preg_match($pattern, $rgbString, $matches)) { $r = $matches['r']; $g = $matches['g']; $b = $matches['b']; $hslArray = rgbToHsl($r, $g, $b); return $hslArray; } }
$b = ($b + $m) * 255; return array(floor($r), floor($g), floor($b)); } $hueAdjustment = -180; $tar = array('red' => 47, 'green' => 116, 'blue' => 118); $img = imagecreatefrompng('core/imageColor/img.png'); $x = imagesx($img); $y = imagesy($img); $yMin = $y / 3; $yMax = $y * 2 / 3; $xMin = $x / 3; $xMax = $x * 2 / 3; $red = imagecolorallocate($img, 255, 0, 0); for ($i = $xMin; $i < $xMax; ++$i) { for ($j = $yMin; $j < $yMax; ++$j) { $ind = imagecolorat($img, $i, $j); $val = imagecolorsforindex($img, $ind); if (getDist($tar, $val) < 65) { $hsl = rgbToHsl($val['red'], $val['green'], $val['blue']); //$h = $hsv['H'] + .2; $h = $hsl[0] + $hueAdjustment; // if ($h > 1) --$h; $rgb = hslToRgb($h, $hsl[1], $hsl[2]); $newCol = imagecolorallocate($img, $rgb[0], $rgb[1], $rgb[2]); imagesetpixel($img, $i, $j, $newCol); } } } $file = 'core/imageColor/result.png'; imagepng($img, $file); echo '<img src="' . $file . '">';
?> ><?php echo $name; ?> </option> <?php } ?> </select> </td></tr> <tr><th scope="row"><?php _e('Text Color', 'easy-watermark'); ?> </th><td> <?php $c = rgbToHsl($color); if ($c[2] < 0.5) { $txtcolor = 'white'; } else { $txtcolor = 'black'; } ?> <input style="background-color:<?php echo $color; ?> ;color:<?php echo $txtcolor; ?> " type="text" maxlength="7" size="7" name="easy-watermark-settings-text[color]" id="ew-color" value="<?php echo $color; ?>
$nn = $n + 0.3 * $n; // Generate the random color hex codes for ($i = 0; $i < $nn; $i++) { $hex_arr[$i] = $digits[mt_rand(0, 15)] . $digits[mt_rand(0, 15)] . $digits[mt_rand(0, 15)] . $digits[mt_rand(0, 15)] . $digits[mt_rand(0, 15)] . $digits[mt_rand(0, 15)]; } // Save random color hex codes into array $hex_arr = array_unique($hex_arr); $hex_arr = array_slice($hex_arr, 0, $n); unset($digits, $nn); $total = count($hex_arr); // Use rgbToHsl to get HSL values for each color, save it all in a big f*****g array foreach ($hex_arr as $val) { $r = hexdec(substr($val, 0, 2)); $g = hexdec(substr($val, 2, 2)); $b = hexdec(substr($val, 4, 2)); $hsl = rgbToHsl($r, $g, $b); if (strlen($val) == 6) { $sl = round(1000 * $hsl['s'] * $hsl['l'], 20); $colors[$val] = array('x' => $val, 'h' => str_pad($hsl['h'], 20, "0"), 's' => str_pad($hsl['s'], 20, "0"), 'l' => str_pad($hsl['l'], 20, "0"), 'sl' => $sl); } unset($key, $val, $g, $r, $b, $hsl, $sl, $hex_arr); // Be cool, pack it in, pack it out. Shakka. } // Get random BG colors for display fun times $colors = sortmulti($colors, 'l', 'desc'); $bg1 = array_slice($colors, 0, 1); $bg1 = array_slice($colors, 1, 2); $colors = sortmulti($colors, 'l', 'asc'); $range = round(count($colors) * 0.09); $text = array_slice($colors, $range, $range + 1); $text = array_slice($colors, $range + 1, $range + 2);