| 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"/><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://sam.zoy.org/wtfpl/COPYING for more details. |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | function unistr_to_ords($str, $encoding = 'UTF-8'){ |
|---|
| 26 | $str = mb_convert_encoding($str, "UCS-4BE", $encoding); |
|---|
| 27 | $result = array(); |
|---|
| 28 | |
|---|
| 29 | for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){ |
|---|
| 30 | $c = mb_substr($str, $i, 1, "UCS-4BE"); |
|---|
| 31 | $val = unpack("N", $c); |
|---|
| 32 | $result[] = $val[1]; |
|---|
| 33 | } |
|---|
| 34 | return $result; |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | function show_figlet($str, $font) { |
|---|
| 38 | $cv = caca_create_canvas(0, 0); |
|---|
| 39 | |
|---|
| 40 | if (!caca_canvas_set_figfont($cv, $font)) { |
|---|
| 41 | return false; |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | $chars = unistr_to_ords($str); |
|---|
| 45 | $color = 0; |
|---|
| 46 | foreach ($chars as $c) { |
|---|
| 47 | caca_set_color_ansi($cv, 1 + (($color += 1) % 13), CACA_WHITE); |
|---|
| 48 | caca_put_figchar($cv, $c); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | echo caca_export_string($cv, "html3"); |
|---|
| 52 | } |
|---|
| 53 | |
|---|
| 54 | $path = "/usr/share/figlet/"; |
|---|
| 55 | if (!is_dir($path)) { |
|---|
| 56 | die("can not open directory $path.\n"); |
|---|
| 57 | } |
|---|
| 58 | |
|---|
| 59 | $dir = opendir($path); |
|---|
| 60 | while (($it = readdir($dir)) != false) { |
|---|
| 61 | if (is_file($path.$it) and ereg("\.[tf]lf$", $it)) { |
|---|
| 62 | echo "<b>font : $it</b>\n"; |
|---|
| 63 | show_figlet(isset($_GET["str"]) ? $_GET["str"] : "Libcaca", $path.$it); |
|---|
| 64 | } |
|---|
| 65 | } |
|---|
| 66 | ?> |
|---|
| 67 | </body> |
|---|
| 68 | </html> |
|---|