Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

135 wiersze
4.1 KiB

  1. #!/usr/bin/php5
  2. <?php
  3. /*
  4. * export libcaca export test program
  5. * Copyright (c) 2008 Benjamin C. Wiley Sittler <bsittler@gmail.com>
  6. *
  7. * This file is a Php port of "examples/export.c"
  8. * which is:
  9. * Copyright (c) 2006 Sam Hocevar <sam@hocevar.net>
  10. * All Rights Reserved
  11. *
  12. * This program is free software. It comes without any warranty, to
  13. * the extent permitted by applicable law. You can redistribute it
  14. * and/or modify it under the terms of the Do What The Fuck You Want
  15. * To Public License, Version 2, as published by Sam Hocevar. See
  16. * http://sam.zoy.org/wtfpl/COPYING for more details.
  17. */
  18. if (php_sapi_name() != "cli") {
  19. die("You have to run this program with php-cli!\n");
  20. }
  21. define('WIDTH', 80);
  22. define('HEIGHT', 32);
  23. $pixels = imagecreatetruecolor(256, 256);
  24. $exports = caca_get_export_list();
  25. if($argc < 2 || $argc > 3)
  26. {
  27. $msg = ($argv[0] . ": wrong argument count\n" .
  28. "usage: " . $argv[0] . " [file] <format>\n" .
  29. "where <format> is one of:\n");
  30. foreach($exports as $format => $name)
  31. $msg .= " \"" . $name . "\" (" . $format . ")\n";
  32. die($msg);
  33. }
  34. if($argc == 2)
  35. {
  36. $file = NULL;
  37. $format = $argv[1];
  38. }
  39. else
  40. {
  41. $file = $argv[1];
  42. $format = $argv[2];
  43. }
  44. if(! array_key_exists($format, $exports))
  45. {
  46. $msg = ($argv[0] . ": unknown format `" . $format . "'\n" .
  47. "please use one of:\n");
  48. foreach($exports as $format => $name)
  49. $msg .= " \"" . $name . "\" (" . $format . ")\n";
  50. die($msg);
  51. }
  52. if($file)
  53. {
  54. $cv = caca_create_canvas(0, 0);
  55. if(caca_import_file($cv, $file, "") < 0)
  56. {
  57. die($argv[0] . ": `" . $file . "' has unknown format\n");
  58. }
  59. }
  60. else
  61. {
  62. $cv = caca_create_canvas(WIDTH, HEIGHT);
  63. for($y = 0; $y < 256; $y++)
  64. {
  65. for($x = 0; $x < 256; $x++)
  66. {
  67. $r = $x;
  68. $g = (255 - $y + $x) / 2;
  69. $b = $y * (255 - $x) / 256;
  70. imagesetpixel($pixels, $x, $y, imagecolorallocate($pixels, $r, $g, $b));
  71. }
  72. }
  73. $dither = caca_create_dither($pixels);
  74. if(($format == "ansi") || ($format == "utf8"))
  75. caca_set_dither_charset($dither, "shades");
  76. caca_dither_bitmap($cv, 0, 0, caca_get_canvas_width($cv),
  77. caca_get_canvas_height($cv), $dither, $pixels);
  78. caca_set_color_ansi($cv, CACA_WHITE, CACA_BLACK);
  79. caca_draw_thin_box($cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  80. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  81. caca_fill_ellipse($cv, WIDTH / 2, HEIGHT / 2,
  82. WIDTH / 4, HEIGHT / 4, ord(' '));
  83. caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
  84. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
  85. " lightgray on black ");
  86. caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
  87. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
  88. " default on transparent ");
  89. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  90. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
  91. " black on white ");
  92. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  93. caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
  94. caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
  95. caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  96. caca_put_str($cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
  97. caca_set_attr($cv, CACA_BOLD);
  98. caca_put_str($cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
  99. caca_set_attr($cv, CACA_BLINK);
  100. caca_put_str($cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
  101. caca_set_attr($cv, CACA_ITALICS);
  102. caca_put_str($cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
  103. caca_set_attr($cv, CACA_UNDERLINE);
  104. caca_put_str($cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
  105. caca_set_attr($cv, 0);
  106. caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
  107. caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  108. for($x = 0; $x < 16; $x++)
  109. {
  110. caca_set_color_argb($cv, 0xff00 | $x, 0xf00f | ($x << 4));
  111. caca_put_char($cv, WIDTH / 2 - 7 + $x, HEIGHT / 2 + 6, ord('#'));
  112. }
  113. }
  114. echo caca_export_string($cv, $format);
  115. ?>