You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. $format = isset($_REQUEST['format']) ? $_REQUEST['format'] : NULL;
  25. if((! $format) || (! array_key_exists($format, $exports)))
  26. {
  27. header("Content-type: text/html; charset=UTF-8");
  28. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  29. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  30. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  31. <head>
  32. <title>libcaca export test program</title>
  33. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  34. </head>
  35. <body>
  36. <form action="#" enctype="multipart/form-data" method="post">
  37. <label for="file">File:</label>
  38. <input name="file" type="file" /> <em>(optional)</em>
  39. <br />
  40. <input type="submit" value="Export" />
  41. <label for="format">as</label>
  42. <select name="format" id="format">
  43. <?php
  44. foreach($exports as $format => $name)
  45. {
  46. ?><option value="<?= htmlspecialchars($format) ?>"<?=
  47. ($format == 'html') ? ' selected="selected"' : '' ?>><?=
  48. htmlspecialchars($name . " (" . $format . ")") ?></option><?php
  49. }
  50. ?>
  51. </select>
  52. </form>
  53. </body>
  54. </html>
  55. <?php
  56. exit(0);
  57. }
  58. if($file)
  59. {
  60. $cv = caca_create_canvas(0, 0);
  61. if(caca_import_file($cv, $file, "") < 0)
  62. {
  63. die($argv[0] . ": `" . $file . "' has unknown format\n");
  64. }
  65. }
  66. else
  67. {
  68. $cv = caca_create_canvas(WIDTH, HEIGHT);
  69. for($y = 0; $y < 256; $y++)
  70. {
  71. for($x = 0; $x < 256; $x++)
  72. {
  73. $r = $x;
  74. $g = (255 - $y + $x) / 2;
  75. $b = $y * (255 - $x) / 256;
  76. imagesetpixel($pixels, $x, $y, imagecolorallocate($pixels, $r, $g, $b));
  77. }
  78. }
  79. $dither = caca_create_dither($pixels);
  80. if(($format == "ansi") || ($format == "utf8"))
  81. caca_set_dither_charset($dither, "shades");
  82. caca_dither_bitmap($cv, 0, 0, caca_get_canvas_width($cv),
  83. caca_get_canvas_height($cv), $dither, $pixels);
  84. caca_set_color_ansi($cv, CACA_WHITE, CACA_BLACK);
  85. caca_draw_thin_box($cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  86. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  87. caca_fill_ellipse($cv, WIDTH / 2, HEIGHT / 2,
  88. WIDTH / 4, HEIGHT / 4, ord(' '));
  89. caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
  90. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
  91. " lightgray on black ");
  92. caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
  93. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
  94. " default on transparent ");
  95. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  96. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
  97. " black on white ");
  98. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  99. caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
  100. caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
  101. caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  102. caca_put_str($cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
  103. caca_set_attr($cv, CACA_BOLD, CACA_DEFAULT);
  104. caca_put_str($cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
  105. caca_set_attr($cv, CACA_BLINK, CACA_DEFAULT);
  106. caca_put_str($cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
  107. caca_set_attr($cv, CACA_ITALICS, CACA_DEFAULT);
  108. caca_put_str($cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
  109. caca_set_attr($cv, CACA_UNDERLINE, CACA_DEFAULT);
  110. caca_put_str($cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
  111. caca_set_attr($cv, 0, CACA_DEFAULT);
  112. caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
  113. caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  114. for($x = 0; $x < 16; $x++)
  115. {
  116. caca_set_color_argb($cv, 0xff00 | $x, 0xf00f | ($x << 4));
  117. caca_put_char($cv, WIDTH / 2 - 7 + $x, HEIGHT / 2 + 6, ord('#'));
  118. }
  119. }
  120. $content_type_map = array(
  121. 'ansi' => 'text/plain; charset=CP437',
  122. 'utf8' => 'text/plain; charset=UTF-8',
  123. 'utf8cr' => 'text/plain; charset=UTF-8',
  124. 'html' => 'text/html; charset=UTF-8',
  125. 'html3' => 'text/html; charset=UTF-8',
  126. 'bbfr' => 'text/plain; charset=UTF-8',
  127. 'irc' => 'text/plain; charset=UTF-8',
  128. 'ps' => 'application/postscript',
  129. 'svg' => 'image/svg+xml',
  130. 'tga' => 'image/x-targa'
  131. );
  132. $download_extension_map = array(
  133. 'ansi' => 'txt',
  134. 'utf8' => 'txt',
  135. 'utf8cr' => 'txt',
  136. 'irc' => 'txt',
  137. 'tga' => 'tga'
  138. );
  139. $inline_extension_map = array(
  140. 'bbfr' => 'txt',
  141. 'ps' => 'ps',
  142. 'svg' => 'svg'
  143. );
  144. if (! array_key_exists($format, $content_type_map))
  145. $content_type = 'application/octet-stream';
  146. else
  147. $content_type = $content_type_map[$format];
  148. header('Content-Type: ' . $content_type);
  149. if (array_key_exists($format, $download_extension_map))
  150. header('Content-Disposition: attachment; filename=export.' . $download_extension_map[$format]);
  151. else if (array_key_exists($format, $inline_extension_map))
  152. header('Content-Disposition: inline; filename=export.' . $inline_extension_map[$format]);
  153. echo caca_export_string($cv, $format);
  154. ?>