/**
 * @param string $input
 *
 * @return bool
 */
function wpml_is_valid_hex_color($input)
{
    if ('transparent' === $input || preg_match('/' . wpml_get_valid_hex_color_pattern() . '/i', $input)) {
        $is_valid = true;
    } else {
        $try_rgb2hex = rgb_to_hex($input);
        $is_valid = $try_rgb2hex ? preg_match('/' . wpml_get_valid_hex_color_pattern() . '/i', $try_rgb2hex) : false;
    }
    return $is_valid;
}
Example #2
0
function get_color_values($image)
{
    $image_x = imagesx($image);
    $image_y = imagesy($image);
    $hex_array = array();
    for ($x = 0; $x < $image_x; $x++) {
        for ($y = 0; $y < $image_y; $y++) {
            $color = imagecolorat($image, $x, $y);
            $red = $color >> 16 & 0xff;
            $green = $color >> 8 & 0xff;
            $blue = $color & 0xff;
            $hex = rgb_to_hex(array($red, $green, $blue));
            array_push($hex_array, $hex);
        }
    }
    return $hex_array;
}
Example #3
0
 /**
  * @param  array $rgb
  *
  * @return string
  */
 function rgb_array_to_hex(array $rgb)
 {
     return rgb_to_hex($rgb['r'], $rgb['g'], $rgb['b']);
 }
Example #4
0
 /**
  * Convert RGB To HEX
  *
  * @return string
  */
 private function rgbToHex()
 {
     return rgb_to_hex($this->red, $this->green, $this->blue);
 }