選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

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