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.

export.php 3.8 KiB

16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
16 vuotta sitten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. $exports = caca_get_export_list();
  27. if($argc < 2 || $argc > 3)
  28. {
  29. $msg = ($argv[0] . ": wrong argument count\n" .
  30. "usage: " . $argv[0] . " [file] <format>\n" .
  31. "where <format> is one of:\n");
  32. foreach($exports as $format => $name)
  33. $msg .= " \"" . $name . "\" (" . $format . ")\n";
  34. die($msg);
  35. }
  36. if($argc == 2)
  37. {
  38. $file = NULL;
  39. $format = $argv[1];
  40. }
  41. else
  42. {
  43. $file = $argv[1];
  44. $format = $argv[2];
  45. }
  46. if(! array_key_exists($format, $exports))
  47. {
  48. $msg = ($argv[0] . ": unknown format `" . $format . "'\n" .
  49. "please use one of:\n");
  50. foreach($exports as $format => $name)
  51. $msg .= " \"" . $name . "\" (" . $format . ")\n";
  52. die($msg);
  53. }
  54. if($file)
  55. {
  56. $cv = caca_create_canvas(0, 0);
  57. if(caca_import_file($cv, $file, "") < 0)
  58. {
  59. die($argv[0] . ": `" . $file . "' has unknown format\n");
  60. }
  61. }
  62. else
  63. {
  64. $cv = caca_create_canvas(WIDTH, HEIGHT);
  65. for($y = 0; $y < 256; $y++)
  66. {
  67. for($x = 0; $x < 256; $x++)
  68. {
  69. $r = $x;
  70. $g = (255 - $y + $x) / 2;
  71. $b = $y * (255 - $x) / 256;
  72. imagesetpixel($pixels, $x, $y, imagecolorallocate($pixels, $r, $g, $b));
  73. }
  74. }
  75. $dither = caca_create_dither($pixels);
  76. if(($format == "ansi") || ($format == "utf8"))
  77. caca_set_dither_charset($dither, "shades");
  78. caca_dither_bitmap($cv, 0, 0, caca_get_canvas_width($cv),
  79. caca_get_canvas_height($cv), $dither, $pixels);
  80. caca_set_color_ansi($cv, CACA_WHITE, CACA_BLACK);
  81. caca_draw_thin_box($cv, 0, 0, WIDTH - 1, HEIGHT - 1);
  82. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  83. caca_fill_ellipse($cv, WIDTH / 2, HEIGHT / 2,
  84. WIDTH / 4, HEIGHT / 4, ord(' '));
  85. caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK);
  86. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 6,
  87. " lightgray on black ");
  88. caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT);
  89. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 5,
  90. " default on transparent ");
  91. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  92. caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 4,
  93. " black on white ");
  94. caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE);
  95. caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]");
  96. caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]");
  97. caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ");
  98. caca_put_str($cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>");
  99. caca_set_attr($cv, CACA_BOLD);
  100. caca_put_str($cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold");
  101. caca_set_attr($cv, CACA_BLINK);
  102. caca_put_str($cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink");
  103. caca_set_attr($cv, CACA_ITALICS);
  104. caca_put_str($cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics");
  105. caca_set_attr($cv, CACA_UNDERLINE);
  106. caca_put_str($cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline");
  107. caca_set_attr($cv, 0);
  108. caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE);
  109. caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA ");
  110. for($x = 0; $x < 16; $x++)
  111. {
  112. caca_set_color_argb($cv, 0xff00 | $x, 0xf00f | ($x << 4));
  113. caca_put_char($cv, WIDTH / 2 - 7 + $x, HEIGHT / 2 + 6, ord('#'));
  114. }
  115. }
  116. echo caca_export_string($cv, $format);
  117. ?>