Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

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