Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: image/png');
- function rgbFromHex($hexValue) {
- //$hexValue = str_replace('#', '', $hexValue);
- //SILLY ME WAS EXPECTING # TO BE PASSED. BUT USING $_GET[] VARIABLES THAT ISN'T POSSIBLE... DAMMIT.
- if (strlen($hexValueValue) == 3) { //CHECK FOR SHORTHAND
- $r = hexdec(substr($hexValueValue, 0, 1) . substr($hexValue, 0, 1));
- $g = hexdec(substr($hexValue, 1, 1) . substr($hexValue, 1, 1));
- $b = hexdec(substr($hexValue, 2, 1) . substr($hexValue, 2, 1));
- } else { //FUNCTION FOR NORMAL 6 DIGIT VALUES
- $r = hexdec(substr($hexValue, 0, 2));
- $g = hexdec(substr($hexValue, 2, 2));
- $b = hexdec(substr($hexValue, 4, 2));
- }
- $rgb = array($r,$g,$b);
- return $rgb;
- }
- if ($_GET['color']) $col = rgbFromHex($_GET['color']); //DON'T DO ANYTHING IF A COLOR ISN'T PROVIDED
- $im = imagecreate(200, 40);
- imagecolorallocate($im, $col[0], $col[1], $col[2]); //FIND A BETTER WAY TO DO THIS.
- imagepng($im);
- //SWEET
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement