Debian Codegraph @

caca-php/examples/www/dithering.php

raw
1 <?php
2 header('Content-Type: text/html; charset=UTF-8');
3 ?>
4 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
5 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6
7 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
8 <head>
9 <title>Caca power!</title>
10 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
11 </head>
12 <body>
13 <?php
14 /*
15 * dithering.php sample program for libcaca php binding
16 * Copyright (c) 2008 Nicolas Vion <[email protected]>
17 *
18 * This program is free software. It comes without any warranty, to
19 * the extent permitted by applicable law. You can redistribute it
20 * and/or modify it under the terms of the Do What the Fuck You Want
21 * to Public License, Version 2, as published by Sam Hocevar. See
22 * http://www.wtfpl.net/ for more details.
23 */
24
25 $src = "logo-caca.png";
26 $img = imagecreatefrompng(dirname(__FILE__)."/".$src);
27 if (!$img) {
28 die("Can not open image.\n");
29 }
30
31 $dither = caca_create_dither($img);
32 if (!$dither) {
33 die("Can not create dither. Maybe you compiled caca-php without gd support.\n");
34 }
35
36 $canvas = caca_create_canvas(100, 40);
37
38 caca_dither_bitmap($canvas, 0, 0, caca_get_canvas_width($canvas), caca_get_canvas_height($canvas), $dither, $img);
39
40 echo caca_export_string($canvas, "html3");
41 echo "<img src=\"./$src\" alt=\"\" />";
42
43 ?>
44 </body>
45 </html>
46