您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

223 行
6.4 KiB

  1. <?php
  2. /*
  3. * export libcaca export test program
  4. * Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
  5. *
  6. * This file is a Php port of "examples/export.c"
  7. * which is:
  8. * Copyright (c) 2006 Sam Hocevar <sam@zoy.org>
  9. * All Rights Reserved
  10. *
  11. * $Id$
  12. *
  13. * This program is free software. It comes without any warranty, to
  14. * the extent permitted by applicable law. You can redistribute it
  15. * and/or modify it under the terms of the Do What The Fuck You Want
  16. * To Public License, Version 2, as published by Sam Hocevar. See
  17. * http://sam.zoy.org/wtfpl/COPYING for more details.
  18. */
  19. define('WIDTH', 80);
  20. define('HEIGHT', 32);
  21. $pixels = imagecreatetruecolor(256, 256);
  22. $exports = caca_get_export_list();
  23. $file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL;
  24. $filename = isset($_FILES['file']) ? $_FILES['file']['name'] : NULL;
  25. $format = isset($_REQUEST['format']) ? $_REQUEST['format'] : NULL;
  26. if((! $format) || (! array_key_exists($format, $exports)))
  27. {
  28. header("Content-type: text/html; charset=UTF-8");
  29. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  30. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  31. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  32. <head>
  33. <title>libcaca export test program</title>
  34. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  35. <script type="text/javascript">
  36. /*<![CDATA[*/
  37. update_preview = function (select)
  38. {
  39. var iframe_map = {
  40. 'html': true,
  41. 'html3': true,
  42. 'bbfr': true
  43. };
  44. if (self.opera
  45. ||
  46. (('' + navigator.userAgent).match(/.*(WebKit|Gecko).*/)))
  47. {
  48. iframe_map['svg'] = true;
  49. }
  50. var e;
  51. try
  52. {
  53. var format = select.options[select.selectedIndex].value;
  54. var newLocation = 'about:blank';
  55. if (iframe_map[format])
  56. {
  57. newLocation = self.location.pathname + '?format=' + encodeURIComponent(format);
  58. }
  59. self.frames[0].location.replace(newLocation, true);
  60. }
  61. catch (e)
  62. {
  63. alert('e' + e);
  64. }
  65. return true;
  66. };
  67. /*]]>*/
  68. </script>
  69. </head>
  70. <body onload="update_preview(document.forms.exportform.elements.format);">
  71. <form id="exportform" name="exportform" action="#" enctype="multipart/form-data" method="post">
  72. <label for="file">File:</label>
  73. <input id="file" name="file" type="file" /> <em>(optional)</em>
  74. <br />
  75. <input type="submit" value="Export" />
  76. <label for="format">as</label>
  77. <select name="format" id="format" onchange="update_preview(this);">
  78. <?php
  79. foreach($exports as $format => $name)
  80. {
  81. ?><option value="<?= htmlspecialchars($format) ?>"<?=
  82. ($format == 'html') ? ' selected="selected"' : '' ?>><?=
  83. htmlspecialchars($name . " (" . $format . ")") ?></option><?php
  84. }
  85. ?>
  86. </select>
  87. </form>
  88. <?php
  89. $export_php = isset($_SERVER['SCRIPT_NAME'])
  90. ?
  91. $_SERVER['SCRIPT_NAME']
  92. :
  93. 'export.php';
  94. ?><iframe frameborder="0" name="preview" id="preview" width="820" height="620" style="margin: 0; padding: 0; border: none; width: 100%"></iframe>
  95. </body>
  96. </html>
  97. <?php
  98. exit(0);
  99. }
  100. if($file)
  101. {
  102. $cv = caca_create_canvas(0, 0);
  103. if(caca_import_file($cv, $file, "") < 0)
  104. {
  105. die("`" . htmlspecialchars($filename) . "' has unknown format\n");
  106. }
  107. }
  108. else
  109. {
  110. $cv = caca_create_canvas(WIDTH, HEIGHT);
  111. for($y = 0; $y < 256; $y++)
  112. {
  113. for($x = 0; $x < 256; $x++)
  114. {
  115. $r = $x;
  116. $g = (255 - $y + $x) / 2;
  117. $b = $y * (255 - $x) / 256;
  118. imagesetpixel($pixels, $x, $y, imagecolorallocate($pixels, $r, $g, $b));
  119. }
  120. }
  121. $dither = caca_create_dither($pixels);
  122. if(($format == "ansi") || ($format == "utf8"))
  123. caca_set_dither_charset($dither, "shades");
  124. caca_dither_bitmap($cv, 0, 0, caca_get_canvas_width($cv),
  125. caca_get_canvas_height($cv), $dither, $pixels);
  126. caca_set_color_ansi($cv, CACA_WHITE, CACA_BLACK);
  127. caca_draw_thin_box($cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  128. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  129. caca_fill_ellipse($cv, WIDTH / 2, HEIGHT / 2,
  130. WIDTH / 4, HEIGHT / 4, ord(' '));
  131. caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
  132. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
  133. " lightgray on black ");
  134. caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
  135. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
  136. " default on transparent ");
  137. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  138. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
  139. " black on white ");
  140. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  141. caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
  142. caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
  143. caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  144. caca_put_str($cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
  145. caca_set_attr($cv, CACA_BOLD);
  146. caca_put_str($cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
  147. caca_set_attr($cv, CACA_BLINK);
  148. caca_put_str($cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
  149. caca_set_attr($cv, CACA_ITALICS);
  150. caca_put_str($cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
  151. caca_set_attr($cv, CACA_UNDERLINE);
  152. caca_put_str($cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
  153. caca_set_attr($cv, 0);
  154. caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
  155. caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  156. for($x = 0; $x < 16; $x++)
  157. {
  158. caca_set_color_argb($cv, 0xff00 | $x, 0xf00f | ($x << 4));
  159. caca_put_char($cv, WIDTH / 2 - 7 + $x, HEIGHT / 2 + 6, ord('#'));
  160. }
  161. }
  162. $content_type_map = array(
  163. 'ansi' => 'text/plain; charset=CP437',
  164. 'utf8' => 'text/plain; charset=UTF-8',
  165. 'utf8cr' => 'text/plain; charset=UTF-8',
  166. 'html' => 'text/html; charset=UTF-8',
  167. 'html3' => 'text/html; charset=UTF-8',
  168. 'bbfr' => 'text/plain; charset=UTF-8',
  169. 'irc' => 'text/plain; charset=UTF-8',
  170. 'ps' => 'application/postscript',
  171. 'svg' => 'image/svg+xml',
  172. 'tga' => 'image/x-targa'
  173. );
  174. $download_extension_map = array(
  175. 'caca' => 'caca',
  176. 'ansi' => 'txt',
  177. 'utf8' => 'txt',
  178. 'utf8cr' => 'txt',
  179. 'irc' => 'txt',
  180. 'tga' => 'tga'
  181. );
  182. $inline_extension_map = array(
  183. 'bbfr' => 'txt',
  184. 'ps' => 'ps',
  185. 'svg' => 'svg'
  186. );
  187. if (! array_key_exists($format, $content_type_map))
  188. $content_type = 'application/octet-stream';
  189. else
  190. $content_type = $content_type_map[$format];
  191. header('Content-Type: ' . $content_type);
  192. if (array_key_exists($format, $download_extension_map))
  193. header('Content-Disposition: attachment; filename=export.' . $download_extension_map[$format]);
  194. else if (array_key_exists($format, $inline_extension_map))
  195. header('Content-Disposition: inline; filename=export.' . $inline_extension_map[$format]);
  196. echo caca_export_string($cv, $format);
  197. ?>