source: libcaca/trunk/caca-php/examples/www/figlet.php @ 3210

Last change on this file since 3210 was 3210, checked in by bsittler, 12 years ago

remove the stylesheet, as it does not seem to help at the moment. also remove the <pre></pre> in figlet.php since it does not seem to make a difference since the table markup includes <tt></tt> inside each cell.

File size: 1.8 KB
Line 
1<?php
2header('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<?php
13/*
14 *  figlet.php      sample program for libcaca php binding
15 *  Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
16 *
17 *  This program is free software. It comes without any warranty, to
18 *  the extent permitted by applicable law. You can redistribute it
19 *  and/or modify it under the terms of the Do What The Fuck You Want
20 *  To Public License, Version 2, as published by Sam Hocevar. See
21 *  http://sam.zoy.org/wtfpl/COPYING for more details.
22 */
23
24function unistr_to_ords($str, $encoding = 'UTF-8'){       
25        $str = mb_convert_encoding($str, "UCS-4BE", $encoding);
26        $result = array();
27
28        for ($i = 0; $i < mb_strlen($str, "UCS-4BE"); $i++){       
29                $c = mb_substr($str, $i, 1, "UCS-4BE");                   
30                $val = unpack("N", $c);           
31                $result[] = $val[1];               
32        }       
33        return $result;
34}
35
36function show_figlet($str, $font) {
37        $cv = caca_create_canvas(0, 0);
38
39        if (!caca_canvas_set_figfont($cv, $font)) {
40                return false;
41        }
42       
43        $chars = unistr_to_ords($str);
44        $color = 0;
45        foreach ($chars as $c) {
46                caca_set_color_ansi($cv, 1 + (($color += 4) % 15), CACA_WHITE);
47                caca_put_figchar($cv, $c);
48        }
49
50        echo caca_export_string($cv, "html3");
51}
52
53$path = "/usr/share/figlet/";
54if (!is_dir($path)) {
55        die("can not open directory $path.\n");
56}
57
58$dir = opendir($path);
59while (($it = readdir($dir)) != false) {
60        if (is_file($path.$it) and ereg("\.[tf]lf$", $it)) {
61                echo "<b>font : $it</b>\n";
62                show_figlet("Libcaca", $path.$it);
63        }
64}
65?>
66</body>
67</html>
Note: See TracBrowser for help on using the repository browser.