1 | <?php |
---|
2 | |
---|
3 | function pig() { |
---|
4 | $pig_str = <<<EOT |
---|
5 | |
---|
6 | _._ _..._ .-', _.._(`)) |
---|
7 | '-. ` ' /-._.-' ',/ |
---|
8 | ) \ '. |
---|
9 | / _ _ | \ |
---|
10 | | a a / PHP | |
---|
11 | \ .-. ; |
---|
12 | '-('' ).-' ,' ; |
---|
13 | '-; | .' |
---|
14 | \ \ / |
---|
15 | | 7 .__ _.-\ \ |
---|
16 | | | | ``/ /` / |
---|
17 | jgs /,_| | /,_/ / |
---|
18 | /,_/ '`-' |
---|
19 | EOT; |
---|
20 | |
---|
21 | $canvas = caca_create_canvas(0, 0); |
---|
22 | caca_set_color_ansi($canvas, CACA_RED, CACA_WHITE); |
---|
23 | caca_import_string($canvas, $pig_str, "text"); |
---|
24 | caca_set_color_ansi($canvas, CACA_BLUE, CACA_LIGHTGRAY); |
---|
25 | caca_put_str($canvas, 0, 0, "Я люблю Либкаку"); |
---|
26 | return $canvas; |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | if (isset($_GET["png"])) { |
---|
31 | $canvas = pig(); |
---|
32 | $font = caca_load_builtin_font("Monospace Bold 12"); |
---|
33 | $width = caca_get_canvas_width($canvas) * caca_get_font_width($font); |
---|
34 | $height = caca_get_canvas_height($canvas) * caca_get_font_height($font); |
---|
35 | $img = imagecreatetruecolor($width, $height); |
---|
36 | caca_render_canvas($canvas, $font, $img); |
---|
37 | header("Content-type: image/png"); |
---|
38 | imagepng($img); |
---|
39 | } |
---|
40 | else { |
---|
41 | |
---|
42 | $render_php = isset($_SERVER['SCRIPT_NAME']) |
---|
43 | ? |
---|
44 | $_SERVER['SCRIPT_NAME'] |
---|
45 | : |
---|
46 | 'render.php'; |
---|
47 | |
---|
48 | ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
---|
49 | "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
---|
50 | |
---|
51 | <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
---|
52 | <head> |
---|
53 | <title>Я люблю Либкаку</title> |
---|
54 | <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> |
---|
55 | </head> |
---|
56 | <body text="silver" bgcolor="black"> |
---|
57 | |
---|
58 | <h1>Text mode:</h1> |
---|
59 | <?echo caca_export_string(pig(), "html3");?> |
---|
60 | |
---|
61 | <h1>Generated image:</h1> |
---|
62 | <a href="<?= htmlspecialchars($render_php) ?>?png=1"><img alt="[PNG]" |
---|
63 | src="<?= htmlspecialchars($render_php) ?>?png=1" border="0" /></a> |
---|
64 | </body> |
---|
65 | </html> |
---|
66 | |
---|
67 | <?php |
---|
68 | } |
---|
69 | |
---|
70 | ?> |
---|