You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

dithering.php 1.2 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  2. <head>
  3. <title>Caca power!</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
  5. <style type="text/css">
  6. </style>
  7. </head>
  8. <body>
  9. <?php
  10. /*
  11. * dithering.php sample program for libcaca php binding
  12. * Copyright (c) 2008 Nicolas Vion <nico@yojik.eu>
  13. *
  14. * This program is free software. It comes without any warranty, to
  15. * the extent permitted by applicable law. You can redistribute it
  16. * and/or modify it under the terms of the Do What The Fuck You Want
  17. * To Public License, Version 2, as published by Sam Hocevar. See
  18. * http://sam.zoy.org/wtfpl/COPYING for more details.
  19. */
  20. $src = "logo-caca.png";
  21. $img = imagecreatefrompng(dirname(__FILE__)."/".$src);
  22. if (!$img) {
  23. die("Can not open image.\n");
  24. }
  25. $dither = caca_create_dither($img);
  26. if (!$dither) {
  27. die("Can not create dither. Maybe you compiled caca-php without gd support.\n");
  28. }
  29. $canvas = caca_create_canvas(100, 40);
  30. caca_dither_bitmap($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img);
  31. echo caca_export_string($canvas, "html3");
  32. echo "<img src='./$src' alt=''/>";
  33. ?>
  34. </body>
  35. </html>