1 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> |
---|
2 | <head> |
---|
3 | <title>Caca power!</title> |
---|
4 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
---|
5 | <style type="text/css"> |
---|
6 | </style> |
---|
7 | </head> |
---|
8 | <body> |
---|
9 | <?php |
---|
10 | /* |
---|
11 | * figlet.php sample program for libcaca php binding |
---|
12 | * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu> |
---|
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 | |
---|
21 | function unistr_to_ords($str, $encoding = 'UTF-8'){ |
---|
22 | $str = mb_convert_encoding($str, "UCS-4BE", $encoding); |
---|
23 | $result = array(); |
---|
24 | |
---|
25 | for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){ |
---|
26 | $c = mb_substr($str, $i, 1, "UCS-4BE"); |
---|
27 | $val = unpack("N", $c); |
---|
28 | $result[] = $val[1]; |
---|
29 | } |
---|
30 | return $result; |
---|
31 | } |
---|
32 | |
---|
33 | function show_figlet($str, $font) { |
---|
34 | $cv = caca_create_canvas(0, 0); |
---|
35 | |
---|
36 | if (!caca_canvas_set_figfont($cv, $font)) { |
---|
37 | return false; |
---|
38 | } |
---|
39 | |
---|
40 | $chars = unistr_to_ords($str); |
---|
41 | $color = 0; |
---|
42 | foreach ($chars as $c) { |
---|
43 | caca_set_color_ansi($cv, 1 + (($color += 4) % 15), CACA_WHITE); |
---|
44 | caca_put_figchar($cv, $c); |
---|
45 | } |
---|
46 | |
---|
47 | echo caca_export_string($cv, "html3"); |
---|
48 | } |
---|
49 | |
---|
50 | $path = "/usr/share/figlet/"; |
---|
51 | if (!is_dir($path)) { |
---|
52 | die("can not open directory $path.\n"); |
---|
53 | } |
---|
54 | |
---|
55 | $dir = opendir($path); |
---|
56 | while (($it = readdir($dir)) != false) { |
---|
57 | if (is_file($path.$it) and ereg("\.[tf]lf$", $it)) { |
---|
58 | echo "<b>font : $it</b>\n<pre>"; |
---|
59 | show_figlet("Libcaca", $path.$it); |
---|
60 | echo "</pre>"; |
---|
61 | } |
---|
62 | } |
---|
63 | ?> |
---|
64 | </body> |
---|
65 | </html> |
---|