No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

figfont.php 1.3 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #!/usr/bin/php5
  2. <?php
  3. /*
  4. * figfont.php sample program for libcaca php binding
  5. * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
  6. *
  7. * This program is free software. It comes without any warranty, to
  8. * the extent permitted by applicable law. You can redistribute it
  9. * and/or modify it under the terms of the Do What The Fuck You Want
  10. * To Public License, Version 2, as published by Sam Hocevar. See
  11. * http://sam.zoy.org/wtfpl/COPYING for more details.
  12. */
  13. function unistr_to_ords($str, $encoding = 'UTF-8'){
  14. $str = mb_convert_encoding($str, "UCS-4BE", $encoding);
  15. $result = array();
  16. for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){
  17. $c = mb_substr($str, $i, 1, "UCS-4BE");
  18. $val = unpack("N", $c);
  19. $result[] = $val[1];
  20. }
  21. return $result;
  22. }
  23. if (php_sapi_name() != "cli") {
  24. die("You have to run this program with php-cli!\n");
  25. }
  26. if ($argc < 3) {
  27. die("Too few arguments.\nUsage: cmd <path of font> <utf8 string>\n");
  28. }
  29. $cv = caca_create_canvas(0, 0);
  30. if (!caca_canvas_set_figfont($cv, $argv[1])) {
  31. die("Could not open font\n");
  32. }
  33. $chars = unistr_to_ords($argv[2]);
  34. $color = 0;
  35. foreach ($chars as $c) {
  36. caca_set_color_ansi($cv, 1 + (($color += 4) % 15), CACA_TRANSPARENT);
  37. caca_put_figchar($cv, $c);
  38. }
  39. echo caca_export_string($cv, "utf8");
  40. ?>