64 lines
1.8 KiB

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