fork download
  1. <?php
  2. header('Content-Type: image/png');
  3. $colornames = array(
  4. "pink" => "FFC0CB",
  5. "lightpink" => "FFB6C1",
  6. "hotpink" => "FF69B4",
  7. "deeppink" => "FF1493",
  8. "palevioletred" => "DB7093",
  9. "mediumvioletred" => "C71585",
  10. "lightsalmon" => "FFA07A",
  11. "salmon" => "FA8072",
  12. "darksalmon" => "E9967A",
  13. "lightcoral" => "F08080",
  14. "indianred" => "CD5C5C",
  15. "crimson" => "DC143C",
  16. "firebrick" => "B22222",
  17. "darkred" => "8B0000",
  18. "red" => "FF0000",
  19. "rlemon" => "C40C0C",
  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. "poop" => "825D1E",
  121. "okok" => "825D1E",
  122. "honeydew" => "F0FFF0",
  123. "mintcream" => "F5FFFA",
  124. "azure" => "F0FFFF",
  125. "aliceblue" => "F0F8FF",
  126. "ghostwhite" => "F8F8FF",
  127. "whitesmoke" => "F5F5F5",
  128. "seashell" => "FFF5EE",
  129. "beige" => "F5F5DC",
  130. "oldlace" => "FDF5E6",
  131. "floralwhite" => "FFFAF0",
  132. "ivory" => "FFFFF0",
  133. "antiquewhite" => "FAEBD7",
  134. "linen" => "FAF0E6",
  135. "lavenderblush" => "FFF0F5",
  136. "mistyrose" => "FFE4E1",
  137. "gainsboro" => "DCDCDC",
  138. "lightgray" => "D3D3D3",
  139. "lightgrey" => "D3D3D3",
  140. "silver" => "C0C0C0",
  141. "darkgray" => "A9A9A9",
  142. "darkgrey" => "A9A9A9",
  143. "gray" => "808080",
  144. "grey" => "808080",
  145. "dimgray" => "696969",
  146. "dimgrey" => "696969",
  147. "lightslategray" => "778899",
  148. "lightslategrey" => "778899",
  149. "slategray" => "708090",
  150. "slategrey" => "708090",
  151. "darkslategray" => "2F4F4F",
  152. "darkslategrey" => "2F4F4F",
  153. "black" => "000000",
  154. "roygbiv" => "red,orange,yellow,green,blue,indigo,violet"
  155. );
  156.  
  157.  
  158. function rgbFromHex($hexValue)
  159. {
  160. if (strlen($hexValue) == 3) { //shorthand check
  161. $r = hexdec(str_repeat($hexValue[0], 2));
  162. $g = hexdec(str_repeat($hexValue[1], 2));
  163. $b = hexdec(str_repeat($hexValue[2], 2));
  164. }
  165. else if (strlen($hexValue) == 6){ //standard hex color
  166. $r = hexdec(substr($hexValue, 0, 2));
  167. $g = hexdec(substr($hexValue, 2, 2));
  168. $b = hexdec(substr($hexValue, 4, 2));
  169. }
  170. else{
  171. $r = 0;
  172. $g = 0;
  173. $b = 0;
  174. }
  175.  
  176. $rgb = array(
  177. $r,
  178. $g,
  179. $b
  180. );
  181. return $rgb;
  182. }
  183.  
  184. function getHexByName($name)
  185. {
  186. global $colornames;
  187. if (isset($colornames[$name])) {
  188. return $colornames[$name];
  189. }
  190. else {
  191. return null;
  192. }
  193. }
  194.  
  195. /*
  196.  * $input - a string, possibly comma-separated list of HexValues and/or color names
  197.  *
  198.  * returns an array of [r, g, b] arrays
  199.  */
  200. function parseColors($input){
  201. $colorArray = array();
  202. $parts = explode(",", $input);
  203.  
  204. foreach($parts as $color){
  205. $byName = getHexByName($color);
  206. if(!isset($byName)){
  207. array_push($colorArray, rgbFromHex($color));
  208. } else{
  209. if (strpos($byName, ",") !== FALSE){
  210. // we're dealing with a multi-part name, eg: roygbiv
  211. foreach(parseColors($byName) as $col){
  212. array_push($colorArray, $col);
  213. }
  214. } else{
  215. array_push($colorArray, rgbFromHex($byName));
  216. }
  217. }
  218. }
  219.  
  220. return $colorArray;
  221. }
  222.  
  223. /*
  224.  * $colorArray - an array of [r, g, b] arrays.
  225.  *
  226.  * returns an array of [r, g, b] arrays.
  227.  */
  228. function interpolateGradient($colorArray){
  229. $output = array();
  230.  
  231. return $output;
  232. }
  233.  
  234. /*
  235.  * $colorArray - an array of [r, g, b] arrays.
  236.  *
  237.  * returns an image.
  238.  */
  239. function createSwatch($colorArray)
  240. {
  241. $img = imagecreate(200, 40);
  242. $colWidth = 200 / count($colorArray);
  243. $x = 0;
  244. foreach($colorArray as $rgb) {
  245. $color = imagecolorallocate($img, $rgb[0], $rgb[1], $rgb[2]);
  246. imagefilledrectangle($img, $x, 0, $x + $colWidth, 40, $color);
  247. $x += $colWidth;
  248. }
  249. return imagepng($img);
  250. }
  251.  
  252. /*
  253. $colors = $_GET['color'];
  254. $gradient = $_GET['gradient'];
  255.  
  256. if (isset($colors)) {
  257. $colorArray = parseColors($colors);
  258. } else if (isset($gradient)){
  259. $colorArray = parseColors($gradient);
  260. }
  261.  
  262. if (isset($colorArray)){
  263. createSwatch($colorArray);
  264. }
  265. */
  266.  
  267. createSwatch(parseColors("aqua,poop,roygbiv,poop,aqua"));
  268.  
  269. ?>
Success #stdin #stdout 0.01s 20608KB
stdin
Standard input is empty
stdout