25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

figfont.php 809 B

123456789101112131415161718192021222324252627282930313233343536
  1. #!/usr/bin/php5
  2. <?php
  3. function unistr_to_ords($str, $encoding = 'UTF-8'){
  4. $str = mb_convert_encoding($str, "UCS-4BE", $encoding);
  5. $result = array();
  6. for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){
  7. $c = mb_substr($str, $i, 1, "UCS-4BE");
  8. $val = unpack("N", $c);
  9. $result[] = $val[1];
  10. }
  11. return $result;
  12. }
  13. if ($argc < 3) {
  14. die("Too few arguments.\nUsage: cmd <path of font> <utf8 string>\n");
  15. }
  16. $cv = caca_create_canvas(0, 0);
  17. if (!caca_canvas_set_figfont($cv, $argv[1])) {
  18. die("Could not open font\n");
  19. }
  20. $chars = unistr_to_ords($argv[2]);
  21. $color = 0;
  22. foreach ($chars as $c) {
  23. caca_set_color_ansi($cv, 1 + (($color += 4) % 15), CACA_TRANSPARENT);
  24. caca_put_figchar($cv, $c);
  25. }
  26. echo caca_export_string($cv, "utf8");
  27. ?>