Advertisement
Guest User

SO hex preview thing

a guest
Jul 24th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.95 KB | None | 0 0
  1. <?php
  2. header('Content-Type: image/png');
  3. function rgbFromHex($hexValue) {
  4.  
  5.     //$hexValue = str_replace('#', '', $hexValue);
  6.     //SILLY ME WAS EXPECTING # TO BE PASSED. BUT USING $_GET[] VARIABLES THAT ISN'T POSSIBLE... DAMMIT.
  7.    
  8.     if (strlen($hexValueValue) == 3) { //CHECK FOR SHORTHAND
  9.         $r = hexdec(substr($hexValueValue, 0, 1) . substr($hexValue, 0, 1));
  10.         $g = hexdec(substr($hexValue, 1, 1) . substr($hexValue, 1, 1));
  11.         $b = hexdec(substr($hexValue, 2, 1) . substr($hexValue, 2, 1));
  12.     } else { //FUNCTION FOR NORMAL 6 DIGIT VALUES
  13.         $r = hexdec(substr($hexValue, 0, 2));
  14.         $g = hexdec(substr($hexValue, 2, 2));
  15.         $b = hexdec(substr($hexValue, 4, 2));
  16.     }
  17.     $rgb = array($r,$g,$b);
  18.    
  19.     return $rgb;
  20. }
  21.  
  22. if ($_GET['color']) $col = rgbFromHex($_GET['color']); //DON'T DO ANYTHING IF A COLOR ISN'T PROVIDED
  23.     $im = imagecreate(200, 40);
  24.     imagecolorallocate($im, $col[0], $col[1], $col[2]); //FIND A BETTER WAY TO DO THIS.
  25.  
  26. imagepng($im);
  27. //SWEET
  28.  
  29.  
  30. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement