fork download
  1. <?php
  2. header('Content-Type: image/png');
  3.  
  4. $colornames = array(
  5. "pink" => "FFC0CB",
  6. "lightpink" => "FFB6C1",
  7. "hotpink" => "FF69B4",
  8. "deeppink" => "FF1493",
  9. "palevioletred" => "DB7093",
  10. "mediumvioletred" => "C71585",
  11. "lightsalmon" => "FFA07A",
  12. "salmon" => "FA8072",
  13. "darksalmon" => "E9967A",
  14. "lightcoral" => "F08080",
  15. "indianred" => "CD5C5C",
  16. "crimson" => "DC143C",
  17. "firebrick" => "B22222",
  18. "darkred" => "8B0000",
  19. "red" => "FF0000",
  20. "orangered" => "FF4500",
  21. "tomato" => "FF6347",
  22. "coral" => "FF7F50",
  23. "darkorange" => "FF8C00",
  24. "orange" => "FFA500",
  25. "gold" => "FFD700",
  26. "yellow" => "FFFF00",
  27. "lightyellow" => "FFFFE0",
  28. "lemonchiffon" => "FFFACD",
  29. "lightgoldenrodyellow" => "FAFAD2",
  30. "papayawhip" => "FFEFD5",
  31. "moccasin" => "FFE4B5",
  32. "peachpuff" => "FFDAB9",
  33. "palegoldenrod" => "EEE8AA",
  34. "khaki" => "F0E68C",
  35. "darkkhaki" => "BDB76B",
  36. "cornsilk" => "FFF8DC",
  37. "blanchedalmond" => "FFEBCD",
  38. "bisque" => "FFE4C4",
  39. "navajowhite" => "FFDEAD",
  40. "wheat" => "F5DEB3",
  41. "burlywood" => "DEB887",
  42. "tan" => "D2B48C",
  43. "rosybrown" => "BC8F8F",
  44. "sandybrown" => "F4A460",
  45. "goldenrod" => "DAA520",
  46. "darkgoldenrod" => "B8860B",
  47. "peru" => "CD853F",
  48. "chocolate" => "D2691E",
  49. "saddlebrown" => "8B4513",
  50. "sienna" => "A0522D",
  51. "brown" => "A52A2A",
  52. "maroon" => "800000",
  53. "darkolivegreen" => "556B2F",
  54. "olive" => "808000",
  55. "olivedrab" => "6B8E23",
  56. "yellowgreen" => "9ACD32",
  57. "limegreen" => "32CD32",
  58. "lime" => "00FF00",
  59. "lawngreen" => "7CFC00",
  60. "chartreuse" => "7FFF00",
  61. "greenyellow" => "ADFF2F",
  62. "springgreen" => "00FF7F",
  63. "mediumspringgreen" => "00FA9A",
  64. "lightgreen" => "90EE90",
  65. "palegreen" => "98FB98",
  66. "darkseagreen" => "8FBC8F",
  67. "mediumseagreen" => "3CB371",
  68. "seagreen" => "2E8B57",
  69. "forestgreen" => "228B22",
  70. "green" => "008000",
  71. "darkgreen" => "006400",
  72. "mediumaquamarine" => "66CDAA",
  73. "aqua" => "00FFFF",
  74. "cyan" => "00FFFF",
  75. "lightcyan" => "E0FFFF",
  76. "paleturquoise" => "AFEEEE",
  77. "aquamarine" => "7FFFD4",
  78. "turquoise" => "40E0D0",
  79. "mediumturquoise" => "48D1CC",
  80. "darkturquoise" => "00CED1",
  81. "lightseagreen" => "20B2AA",
  82. "cadetblue" => "5F9EA0",
  83. "darkcyan" => "008B8B",
  84. "teal" => "008080",
  85. "lightsteelblue" => "B0C4DE",
  86. "powderblue" => "B0E0E6",
  87. "lightblue" => "ADD8E6",
  88. "skyblue" => "87CEEB",
  89. "lightskyblue" => "87CEFA",
  90. "deepskyblue" => "00BFFF",
  91. "dodgerblue" => "1E90FF",
  92. "cornflowerblue" => "6495ED",
  93. "steelblue" => "4682B4",
  94. "royalblue" => "4169E1",
  95. "blue" => "0000FF",
  96. "mediumblue" => "0000CD",
  97. "darkblue" => "00008B",
  98. "navy" => "000080",
  99. "midnightblue" => "191970",
  100. "lavender" => "E6E6FA",
  101. "thistle" => "D8BFD8",
  102. "plum" => "DDA0DD",
  103. "violet" => "EE82EE",
  104. "orchid" => "DA70D6",
  105. "fuchsia" => "FF00FF",
  106. "magenta" => "FF00FF",
  107. "mediumorchid" => "BA55D3",
  108. "mediumpurple" => "9370DB",
  109. "blueviolet" => "8A2BE2",
  110. "darkviolet" => "9400D3",
  111. "darkorchid" => "9932CC",
  112. "darkmagenta" => "8B008B",
  113. "purple" => "800080",
  114. "indigo" => "4B0082",
  115. "darkslateblue" => "483D8B",
  116. "slateblue" => "6A5ACD",
  117. "mediumslateblue" => "7B68EE",
  118. "white" => "FFFFFF",
  119. "snow" => "FFFAFA",
  120. "honeydew" => "F0FFF0",
  121. "mintcream" => "F5FFFA",
  122. "azure" => "F0FFFF",
  123. "aliceblue" => "F0F8FF",
  124. "ghostwhite" => "F8F8FF",
  125. "whitesmoke" => "F5F5F5",
  126. "seashell" => "FFF5EE",
  127. "beige" => "F5F5DC",
  128. "oldlace" => "FDF5E6",
  129. "floralwhite" => "FFFAF0",
  130. "ivory" => "FFFFF0",
  131. "antiquewhite" => "FAEBD7",
  132. "linen" => "FAF0E6",
  133. "lavenderblush" => "FFF0F5",
  134. "mistyrose" => "FFE4E1",
  135. "gainsboro" => "DCDCDC",
  136. "lightgray" => "D3D3D3",
  137. "lightgrey" => "D3D3D3",
  138. "silver" => "C0C0C0",
  139. "darkgray" => "A9A9A9",
  140. "darkgrey" => "A9A9A9",
  141. "gray" => "808080",
  142. "grey" => "808080",
  143. "dimgray" => "696969",
  144. "dimgrey" => "696969",
  145. "lightslategray" => "778899",
  146. "lightslategrey" => "778899",
  147. "slategray" => "708090",
  148. "slategrey" => "708090",
  149. "darkslategray" => "2F4F4F",
  150. "darkslategrey" => "2F4F4F",
  151. "black" => "000000"
  152. );
  153.  
  154. function rgbFromHex($hexValue) {
  155.  
  156. //$hexValue = str_replace('#', '', $hexValue);
  157. //SILLY ME WAS EXPECTING # TO BE PASSED. BUT USING $_GET[] VARIABLES THAT ISN'T POSSIBLE... DAMMIT.
  158.  
  159. if (strlen($hexValue) == 3) { //CHECK FOR SHORTHAND
  160. $r = hexdec(substr($hexValue, 0, 1) . substr($hexValue, 0, 1));
  161. $g = hexdec(substr($hexValue, 1, 1) . substr($hexValue, 1, 1));
  162. $b = hexdec(substr($hexValue, 2, 1) . substr($hexValue, 2, 1));
  163. } else { //FUNCTION FOR NORMAL 6 DIGIT VALUES
  164. $r = hexdec(substr($hexValue, 0, 2));
  165. $g = hexdec(substr($hexValue, 2, 2));
  166. $b = hexdec(substr($hexValue, 4, 2));
  167. }
  168. $rgb = array($r,$g,$b);
  169.  
  170. return $rgb;
  171. }
  172. function rgbFromName($name){
  173. global $colornames;
  174. if ($colornames[$name]){return rgbFromHex($colornames[$name]);}
  175. else {return null;}
  176. }
  177.  
  178. function createSwatch($colors){
  179. $colArray = explode(",", $colors);
  180. $colWidth = 200 / count($colArray);
  181. $im = imagecreate(200, 40);
  182. $x = 0;
  183.  
  184. foreach($colArray as $col){
  185. if (is_array($rgb)) $rgb = rgbFromName(strtolower($col));
  186. if (!$rgb) $rgb = rgbFromHex($col); //DON'T DO ANYTHING IF A COLOR ISN'T PROVIDED
  187. $color = imagecolorallocate($im, $rgb[0], $rgb[1], $rgb[2]); //FIND A BETTER WAY TO DO THIS.
  188.  
  189. imagefilledrectangle($im, $x, 0, $x + $colWidth, 40, $color);
  190. $x += $colWidth;
  191. }
  192.  
  193. return imagepng($im);
  194. }
  195.  
  196. createSwatch('ff0000,00ff00,00f,ff0,0ff,red,green,blue,black,yellow,orange,PURPLE,WhiteSmoke')
  197. ?>
Success #stdin #stdout #stderr 0.01s 20560KB
stdin
Standard input is empty
stdout
stderr
PHP Notice:  Undefined variable: rgb in /home/a3DXca/prog.php on line 185
PHP Notice:  Undefined variable: rgb in /home/a3DXca/prog.php on line 186
PHP Notice:  Undefined index: 00ff00 in /home/a3DXca/prog.php on line 174
PHP Notice:  Undefined index: 00f in /home/a3DXca/prog.php on line 174
PHP Notice:  Undefined index: ff0 in /home/a3DXca/prog.php on line 174
PHP Notice:  Undefined index: 0ff in /home/a3DXca/prog.php on line 174