source: libcaca/trunk/caca-php/examples/www/cacainfo.php @ 3215

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

add missing whitespace before /> so that the XHTML works in more plain-HTML parsers; quote attributes in double quotes rather than single quotes for the same reason

File size: 2.6 KB
RevLine 
[3204]1<?php
2header('Content-Type: text/html; charset=UTF-8');
3?>
[3186]4<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
7<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
[3178]8<?php
9/*
10 *  cacainfo.php      sample program for libcaca php binding
11 *  Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
12 *
13 *  This program is free software. It comes without any warranty, to
14 *  the extent permitted by applicable law. You can redistribute it
15 *  and/or modify it under the terms of the Do What The Fuck You Want
16 *  To Public License, Version 2, as published by Sam Hocevar. See
17 *  http://sam.zoy.org/wtfpl/COPYING for more details.
18 */
[3183]19?>
20<head>
21<title>sample program for libcaca php binding</title>
[3215]22<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
[3183]23</head>
[3185]24<body text="silver" bgcolor="black">
[3183]25<?php
[3178]26
27//--- Just for fun ---//
28
29function just_for_fun() {
30
31$moo = <<<EOT
32         (__) 
33         (oo)
34   /------\/
35  / |    ||   
36 *  /\---/\
37    ~~   ~~   
38EOT;
39
40        $cv = caca_create_canvas(0, 0);
41        caca_set_color_ansi($cv, CACA_LIGHTBLUE, CACA_DEFAULT);
42        caca_import_string($cv, $moo, "text");
43
44        for($j = 0; $j < caca_get_canvas_height($cv); $j++) {
45                for($i = 0; $i < caca_get_canvas_width($cv); $i += 2) {
46                        caca_set_color_ansi($cv, (caca_rand(1, 10) > 5 ? CACA_LIGHTBLUE  : CACA_WHITE), CACA_DEFAULT);
47                        $a = caca_get_attr($cv, -1, -1);
48                        caca_put_attr($cv, $i, $j, $a);
49                        caca_put_attr($cv, $i + 1, $j, $a);
50                }
51        }
52        caca_set_color_ansi($cv, CACA_LIGHTGREEN, CACA_DEFAULT);
53        caca_put_str($cv, 8, 0, "Moo!");
54        caca_set_color_ansi($cv, CACA_LIGHTRED, CACA_DEFAULT);
55        caca_put_char($cv, 8, 1, hexdec("2765")); //U+2765
56        caca_put_char($cv, 10, 1, hexdec("2764")); //U+2764
57        echo caca_export_string($cv, "html3");
58}
59       
60
61just_for_fun();
62
[3183]63?>
64<?php
65
[3178]66//--- Show caca's information ---//
67
[3185]68?>
69<p>libcaca version: <?php echo htmlspecialchars(caca_get_version()); ?></p>
70
71<p>Available drivers:</p>
72<ul>
73<?php
[3178]74$list = caca_get_display_driver_list();
75foreach($list as $type => $name)
[3185]76        echo '<li>' . htmlspecialchars("$name ($type)") . '</li>';
77?>
78</ul>
[3178]79
[3185]80<p>Available import formats:</p>
81<ul>
82<?php
[3178]83$list = caca_get_import_list();
84foreach($list as $format => $name)
[3185]85        echo '<li>' . htmlspecialchars("$name ($format)") . '</li>';
86?>
87</ul>
[3178]88
[3186]89<p>Available export formats:</p>
[3185]90<ul>
91<?php
[3178]92$list = caca_get_export_list();
93foreach($list as $format => $name)
[3185]94        echo '<li>' . htmlspecialchars("$name ($format)") . '</li>';
95?>
96</ul>
[3178]97
[3185]98<p>Available caca fonts:</p>
99<ul>
100<?php
[3178]101$list = caca_get_font_list();
102foreach($list as $name)
[3185]103        echo '<li>' . htmlspecialchars("$name") . '</li>';
104?>
105</ul>
[3178]106
107</body>
[3198]108</html>
Note: See TracBrowser for help on using the repository browser.