Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

69 righe
2.0 KiB

  1. <?php
  2. header('Content-Type: text/html; charset=UTF-8');
  3. ?>
  4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  5. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  6. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  7. <head>
  8. <title>Caca power!</title>
  9. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
  10. </head>
  11. <body>
  12. <form method="get" action="#"><input name="str" value="<?= htmlspecialchars(isset($_GET["str"]) ? $_GET["str"] : "Libcaca") ?>" /><input type="submit" value="OK" /></form>
  13. <?php
  14. /*
  15. * figlet.php sample program for libcaca php binding
  16. * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
  17. *
  18. * This program is free software. It comes without any warranty, to
  19. * the extent permitted by applicable law. You can redistribute it
  20. * and/or modify it under the terms of the Do What the Fuck You Want
  21. * to Public License, Version 2, as published by Sam Hocevar. See
  22. * http://www.wtfpl.net/ for more details.
  23. */
  24. function unistr_to_ords($str, $encoding = 'UTF-8'){
  25. $str = mb_convert_encoding($str, "UCS-4BE", $encoding);
  26. $result = array();
  27. for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){
  28. $c = mb_substr($str, $i, 1, "UCS-4BE");
  29. $val = unpack("N", $c);
  30. $result[] = $val[1];
  31. }
  32. return $result;
  33. }
  34. function show_figlet($str, $font) {
  35. $cv = caca_create_canvas(0, 0);
  36. if (!caca_canvas_set_figfont($cv, $font)) {
  37. return false;
  38. }
  39. $chars = unistr_to_ords($str);
  40. $color = 0;
  41. foreach ($chars as $c) {
  42. caca_set_color_ansi($cv, 1 + (($color += 1) % 13), CACA_WHITE);
  43. caca_put_figchar($cv, $c);
  44. }
  45. echo caca_export_string($cv, "html3");
  46. }
  47. $path = "/usr/share/figlet/";
  48. if (!is_dir($path)) {
  49. die("can not open directory $path.\n");
  50. }
  51. $dir = opendir($path);
  52. while (($it = readdir($dir)) != false) {
  53. if (is_file($path.$it) and ereg("\.[tf]lf$", $it)) {
  54. echo "<b>font : $it</b>\n";
  55. show_figlet(isset($_GET["str"]) ? $_GET["str"] : "Libcaca", $path.$it);
  56. }
  57. }
  58. ?>
  59. </body>
  60. </html>