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

Last change on this file since 3211 was 3211, checked in by nico, 12 years ago
  • Add an input box in sample web page figlet.php
File size: 1.9 KB
RevLine 
[3204]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">
[3189]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>
[3211]12<form method="get" action=""><input name="str"/><input type="submit" value="OK"/></form>
[3189]13<?php
14/*
[3191]15 *  figlet.php      sample program for libcaca php binding
[3189]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
25function 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
37function 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 += 4) % 15), CACA_WHITE);
48                caca_put_figchar($cv, $c);
49        }
50
51        echo caca_export_string($cv, "html3");
52}
53
[3191]54$path = "/usr/share/figlet/";
55if (!is_dir($path)) {
56        die("can not open directory $path.\n");
57}
58
59$dir = opendir($path);
[3189]60while (($it = readdir($dir)) != false) {
61        if (is_file($path.$it) and ereg("\.[tf]lf$", $it)) {
[3210]62                echo "<b>font : $it</b>\n";
[3211]63                show_figlet(isset($_GET["str"]) ? $_GET["str"] : "Libcaca", $path.$it);
[3189]64        }
65}
66?>
67</body>
68</html>
Note: See TracBrowser for help on using the repository browser.