Returns a color representation for GD based on a color string.

Examples of valid color strings:
- black
- white
- purple
- #00FFCC
- 00FFCC

@param string   $color
@param resource $resource

@return int
771133
public static function load($color, $resource)
    {
        if ($color === 'transparent') {

            return imagecolorallocatealpha($resource, 0, 0, 0, 127);
        }

        $gdpixel = new GDPixel($color);

        return imagecolorallocate($resource, $gdpixel->channelR, $gdpixel->channelG, $gdpixel->channelB);
    }
208334
protected function toHex($color)
	    {
	        $rgb = $this->getRGBComponents($color);

	        return sprintf('#%02X%02X%02X', $rgb[0], $rgb[1], $rgb[2]);
	    }
1174402
public function getResourceId($resource): string
    {
        if (is_resource($resource)) {
            $data = stream_get_meta_data($resource);
            $resource = $data['wrapper_data'];
        }

        return spl_object_hash($resource);
    }
150549
public static function Hex2Rgb( string $color )
   {

      if ( $color[ 0 ] == '#' )
      {
         $color = \substr( $color, 1 );
      }

      if ( \strlen( $color ) == 8 )
      {
         $color = \substr( $color, 2 );
      }

      if ( \strlen( $color ) == 6 )
      {
         $r = $color[ 0 ] . $color[ 1 ];
         $g = $color[ 2 ] . $color[ 3 ];
         $b = $color[ 4 ] . $color[ 5 ];
      }
      else if ( \strlen( $color ) == 3 )
      {
         $r = $color[ 0 ] . $color[ 0 ];
         $g = $color[ 1 ] . $color[ 1 ];
         $b = $color[ 2 ] . $color[ 2 ];
      }
      else if ( \strlen( $color ) == 2 )
      {
         $r = $color;
         $g = $color;
         $b = $color;
      }
      else
      {
         return false;
      }

      return [ \hexdec( $r ), \hexdec( $g ), \hexdec( $b ) ];

   }
297701
public function themePath(string $resource): string
    {
        if (null === $this->theme) {
            return $resource;
        }

        if (file_exists($this->sourceDirectory.'/'.$resource)) {
            return $resource;
        }

        $themeResource = $this->findThemeResource($this->theme, $resource);
        if (null !== $themeResource) {
            return $themeResource;
        }

        if (isset($this->theme['parent'])) {
            $themeResource = $this->findThemeResource($this->theme['parent'], $resource);
            if (null !== $themeResource) {
                return $themeResource;
            }
        }

        return $resource;
    }
432871
public static function rgb(Color $color)
    {
        return sprintf(
            'rgb(%d, %d, %d)',
            $color->getRgb()['r'],
            $color->getRgb()['g'],
            $color->getRgb()['b']
        );
    }
695263
private static String colorString(Color color) {
		return color.getRed() + "," + color.getGreen() + "," + color.getBlue()
				+ "," + color.getAlpha();
	}
766928
public function getHslaString(Color $color)
    {
        return 'hsla('. round($color->hue) . ', ' . round($color->saturation * 100) . '%, ' . round($color->lightness * 100) . '%, ' . $color->alpha . ')';
    }
573998
public function getRgbByColor($color) {
		$result = imagecolorsforindex($this->image, $color);
		return array(
			$result['red'],
			$result['green'],
			$result['blue']
		);
	}
653731
protected static function intColorToLab($color)
    {
        return self::xyzToLab(
            self::srgbToXyz(
                self::rgbToSrgb(
                    [
                        'R' => ($color >> 16) & 0xFF,
                        'G' => ($color >> 8) & 0xFF,
                        'B' => $color & 0xFF,
                    ]
                )
            )
        );
    }
579510
public function colour($string, $colour)
    {
        try {
            return $this->color->__invoke($string)
                ->apply($colour)
                ->__toString();
        } catch (NoStyleFoundException $e) {
            return $string;
        }
    }
215058
public static function parse($color) 
    {
        if (gettype($color) == "integer") {
            return $color & 0xffffffff;
        }

        $color = "$color";

        if (preg_match('/^#?[0-9a-fA-F]+$/', $color)) {
            $hexColor = $color; 
            if ($hexColor[0] == '#') {
                $hexColor = substr($hexColor, 1);
            }

            switch (strlen($hexColor)) {
                case 3:
                    $numeric = intval($hexColor, 16);
                    return (
                        (($numeric & 0xf00) << 20) |
                        (($numeric & 0xf00) << 16) |
                        (($numeric & 0x0f0) << 16) |
                        (($numeric & 0x0f0) << 12) |
                        (($numeric & 0x00f) << 12) |
                        (($numeric & 0x00f) << 8) | 
                        0xff);
                case 6:
                    return (intval($hexColor, 16) << 8) | 0xff;
                case 8:
                    // Workaround to cope with PHP limitation of intval
                    $numeric = 
                        (intval(substr($hexColor, 0, 4), 16) << 16) |
                        (intval(substr($hexColor, 4, 4), 16));
                    return $numeric;
            }
        }

        throw new \InvalidArgumentException("Invalid color '$color'.");
    }
723612
public static function hex2rgb(string $colour)
    {
        if ($colour[0] == '#')
            $colour = substr($colour, 1);

        if (strlen($colour) == 6)
            list($r, $g, $b) = array($colour[0] . $colour[1], $colour[2] . $colour[3], $colour[4] . $colour[5]);
        elseif (strlen($colour) == 3)
            list($r, $g, $b) = array($colour[0] . $colour[0], $colour[1] . $colour[1], $colour[2] . $colour[2]);
        else
            return false;

        $r = hexdec($r);
        $g = hexdec($g);
        $b = hexdec($b);
        return array('red' => $r, 'green' => $g, 'blue' => $b);
    }
12521
public function setColor($color)
    {
        $allowed_values = array('#ffffff', '#ffff01', '#ff6600', '#fe0000', '#9a0000', '#660066', '#0000fe', '#0099ff', '#01ffff', '#00ff33', '#349800', '#006634', '#666666', '#999999', '#e6e6e6', '#ffffcd', '#99ffff', '#ccff9a');
        if (!is_null($color) && (!in_array($color, $allowed_values))) {
            throw new \InvalidArgumentException("Invalid value for 'color', must be one of '#ffffff', '#ffff01', '#ff6600', '#fe0000', '#9a0000', '#660066', '#0000fe', '#0099ff', '#01ffff', '#00ff33', '#349800', '#006634', '#666666', '#999999', '#e6e6e6', '#ffffcd', '#99ffff', '#ccff9a'");
        }
        $this->container['color'] = $color;

        return $this;
    }
345073
public function getColorWithRGB($color) {
		if (func_num_args() == 1 && is_int($color)) {
			return $color;
		}
		if (is_string($color)) {
			$color = self::transformRGB($color);
		} elseif(func_num_args() == 3) {
			$color = func_get_args();
		}
		return imagecolorallocate($this->image, $color[0], $color[1], $color[2]);
	}
377743
public function getColorDifference($color1, $color2): int
    {
        return Plugin::$plugin->color->getColorDifference($color1, $color2);
    }
137074
public function getRgbaString(Color $color)
    {
        return 'rgba('. $color->red . ', ' . $color->green . ', ' . $color->blue . ', ' . $color->alpha . ')';
    }