73 abstract public function getHex($prefix);
105 $this->
parse($value);
118 case is_string($value):
126 case is_array($value):
130 case is_object($value):
134 case is_null($value):
139 throw new \Intervention\Image\Exception\NotReadableException(
140 "Color format ({$value}) cannot be read."
155 switch (strtolower($type)) {
161 return $this->
getHex(
'#');
175 throw new \Intervention\Image\Exception\NotSupportedException(
176 "Color format ({$type}) is not supported."
192 $hexPattern =
'/^#?([a-f0-9]{1,2})([a-f0-9]{1,2})([a-f0-9]{1,2})$/i';
195 $rgbPattern =
'/^rgb ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3})\)$/i';
198 $rgbaPattern =
'/^rgba ?\(([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9]{1,3}), ?([0-9.]{1,4})\)$/i';
200 if (preg_match($hexPattern, $value, $matches)) {
202 $result[0] = strlen($matches[1]) ==
'1' ? hexdec($matches[1].$matches[1]) : hexdec($matches[1]);
203 $result[1] = strlen($matches[2]) ==
'1' ? hexdec($matches[2].$matches[2]) : hexdec($matches[2]);
204 $result[2] = strlen($matches[3]) ==
'1' ? hexdec($matches[3].$matches[3]) : hexdec($matches[3]);
206 } elseif (preg_match($rgbPattern, $value, $matches)) {
208 $result[0] = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0;
209 $result[1] = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0;
210 $result[2] = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0;
212 } elseif (preg_match($rgbaPattern, $value, $matches)) {
214 $result[0] = ($matches[1] >= 0 && $matches[1] <= 255) ? intval($matches[1]) : 0;
215 $result[1] = ($matches[2] >= 0 && $matches[2] <= 255) ? intval($matches[2]) : 0;
216 $result[2] = ($matches[3] >= 0 && $matches[3] <= 255) ? intval($matches[3]) : 0;
217 $result[3] = ($matches[4] >= 0 && $matches[4] <= 1) ? $matches[4] : 0;
219 throw new \Intervention\Image\Exception\NotReadableException(
220 "Unable to read color ({$value})."