- Timestamp:
- Nov 2, 2008, 5:10:50 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca-php/examples/www/render.php
r3203 r3205 1 1 <?php 2 $pngmode = isset($_REQUEST['png']) ? ($_REQUEST['png'] != '') : false;3 2 4 if ($pngmode) 5 header('Content-Type: image/png'); 6 else 7 header('Content-Type: text/html; charset=UTF-8'); 8 9 if (! $pngmode) 10 { 11 ?> 12 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 13 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 14 15 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 16 <head> 17 <title>Я люблю Либкаку</title> 18 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 19 <link rel="StyleSheet" href="caca-php.css" type="text/css" /> 20 </head> 21 <body text="silver" bgcolor="black"> 22 <?php 23 ; 24 } 3 function pig() { 25 4 $pig_str = <<<EOT 26 5 … … 40 19 EOT; 41 20 42 $canvas = caca_create_canvas(0, 0);43 caca_set_color_ansi($canvas, CACA_RED, CACA_WHITE);44 caca_import_string($canvas, $pig_str, "text");45 caca_set_color_ansi($canvas, CACA_BLUE, CACA_LIGHTGRAY);46 caca_put_str($canvas, 0, 0, "Я люблю Либкаку");47 if (! $pngmode) 48 echo caca_export_string($canvas, "html3"); 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 } 49 28 50 $font = caca_load_builtin_font("Monospace Bold 12");51 29 52 $width = caca_get_canvas_width($canvas) * caca_get_font_width($font); 53 $height = caca_get_canvas_height($canvas) * caca_get_font_height($font); 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 ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 42 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 54 43 55 $img = imagecreatetruecolor($width, $height); 44 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 45 <head> 46 <title>Я люблю Либкаку</title> 47 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> 48 <link rel="StyleSheet" href="caca-php.css" type="text/css" /> 49 </head> 50 <body text="silver" bgcolor="black"> 56 51 57 caca_render_canvas($canvas, $font, $img); 52 <h1>Text mode:</h1> 53 <?echo caca_export_string(pig(), "html3");?> 58 54 59 if ($pngmode) 60 imagepng($img); 61 else 62 { 63 ?> 64 <form action="#"> 65 <label for="png">Please, open new created png file:</label> 66 <input type="submit" id="png" name="png" value="Display" /> 67 </form> 55 <h1>Generated image:</h1> 56 <img src="render.php?png=1"/> 68 57 </body> 69 58 </html> 59 70 60 <?php 71 ;72 61 } 62 63 ?>
Note: See TracChangeset
for help on using the changeset viewer.