Browse Source

* Change structure of sample file render.php

tags/v0.99.beta17
Nicolas Vion nico 16 years ago
parent
commit
74475a3583
1 changed files with 36 additions and 45 deletions
  1. +36
    -45
      caca-php/examples/www/render.php

+ 36
- 45
caca-php/examples/www/render.php View File

@@ -1,27 +1,6 @@
<?php
$pngmode = isset($_REQUEST['png']) ? ($_REQUEST['png'] != '') : false;

if ($pngmode)
header('Content-Type: image/png');
else
header('Content-Type: text/html; charset=UTF-8');

if (! $pngmode)
{
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Я люблю Либкаку</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="StyleSheet" href="caca-php.css" type="text/css" />
</head>
<body text="silver" bgcolor="black">
<?php
;
}
function pig() {
$pig_str = <<<EOT
_._ _..._ .-', _.._(`))
@@ -39,34 +18,46 @@ $pig_str = <<<EOT
/,_/ '`-'
EOT;

$canvas = caca_create_canvas(0, 0);
caca_set_color_ansi($canvas, CACA_RED, CACA_WHITE);
caca_import_string($canvas, $pig_str, "text");
caca_set_color_ansi($canvas, CACA_BLUE, CACA_LIGHTGRAY);
caca_put_str($canvas, 0, 0, "Я люблю Либкаку");
if (! $pngmode)
echo caca_export_string($canvas, "html3");
$canvas = caca_create_canvas(0, 0);
caca_set_color_ansi($canvas, CACA_RED, CACA_WHITE);
caca_import_string($canvas, $pig_str, "text");
caca_set_color_ansi($canvas, CACA_BLUE, CACA_LIGHTGRAY);
caca_put_str($canvas, 0, 0, "Я люблю Либкаку");
return $canvas;
}

$font = caca_load_builtin_font("Monospace Bold 12");

$width = caca_get_canvas_width($canvas) * caca_get_font_width($font);
$height = caca_get_canvas_height($canvas) * caca_get_font_height($font);
if (isset($_GET["png"])) {
$canvas = pig();
$font = caca_load_builtin_font("Monospace Bold 12");
$width = caca_get_canvas_width($canvas) * caca_get_font_width($font);
$height = caca_get_canvas_height($canvas) * caca_get_font_height($font);
$img = imagecreatetruecolor($width, $height);
caca_render_canvas($canvas, $font, $img);
header("Content-type: image/png");
imagepng($img);
}
else {
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

$img = imagecreatetruecolor($width, $height);
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Я люблю Либкаку</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<link rel="StyleSheet" href="caca-php.css" type="text/css" />
</head>
<body text="silver" bgcolor="black">

caca_render_canvas($canvas, $font, $img);
<h1>Text mode:</h1>
<?echo caca_export_string(pig(), "html3");?>

if ($pngmode)
imagepng($img);
else
{
?>
<form action="#">
<label for="png">Please, open new created png file:</label>
<input type="submit" id="png" name="png" value="Display" />
</form>
<h1>Generated image:</h1>
<img src="render.php?png=1"/>
</body>
</html>

<?php
;
}
}

?>

Loading…
Cancel
Save