| 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 |
header("Content-type: text/html; charset=UTF-8"); |
| 49 |
|
| 50 |
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
| 51 |
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
| 52 |
|
| 53 |
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
| 54 |
<head> |
| 55 |
<title>Я люблю Либкаку</title> |
| 56 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 57 |
</head> |
| 58 |
<body text="silver" bgcolor="black"> |
| 59 |
|
| 60 |
<h1>Text mode:</h1> |
| 61 |
<?echo caca_export_string(pig(), "html3");?> |
| 62 |
|
| 63 |
<h1>Generated image:</h1> |
| 64 |
<a href="<?= htmlspecialchars($render_php) ?>?png=1"><img alt="[PNG]" |
| 65 |
src="<?= htmlspecialchars($render_php) ?>?png=1" border="0" /></a> |
| 66 |
</body> |
| 67 |
</html> |
| 68 |
|
| 69 |
<?php |
| 70 |
} |
| 71 |
|
| 72 |
?> |