| 1 |
#!/usr/bin/php5 |
| 2 |
<?php |
| 3 |
/* |
| 4 |
* export libcaca export test program |
| 5 |
* Copyright (c) 2008 Benjamin C. Wiley Sittler <[email protected]> |
| 6 |
* |
| 7 |
* This file is a Php port of "examples/export.c" |
| 8 |
* which is: |
| 9 |
* Copyright (c) 2006 Sam Hocevar <[email protected]> |
| 10 |
* All Rights Reserved |
| 11 |
* |
| 12 |
* This program is free software. It comes without any warranty, to |
| 13 |
* the extent permitted by applicable law. You can redistribute it |
| 14 |
* and/or modify it under the terms of the Do What the Fuck You Want |
| 15 |
* to Public License, Version 2, as published by Sam Hocevar. See |
| 16 |
* http://www.wtfpl.net/ for more details. |
| 17 |
*/ |
| 18 |
|
| 19 |
if (php_sapi_name() != "cli") { |
| 20 |
die("You have to run this program with php-cli!\n"); |
| 21 |
} |
| 22 |
|
| 23 |
define('WIDTH', 80); |
| 24 |
define('HEIGHT', 32); |
| 25 |
|
| 26 |
$pixels = imagecreatetruecolor(256, 256); |
| 27 |
|
| 28 |
$exports = caca_get_export_list(); |
| 29 |
|
| 30 |
if($argc < 2 || $argc > 3) |
| 31 |
{ |
| 32 |
$msg = ($argv[0] . ": wrong argument count\n" . |
| 33 |
"usage: " . $argv[0] . " [file] <format>\n" . |
| 34 |
"where <format> is one of:\n"); |
| 35 |
foreach($exports as $format => $name) |
| 36 |
$msg .= " \"" . $name . "\" (" . $format . ")\n"; |
| 37 |
die($msg); |
| 38 |
} |
| 39 |
|
| 40 |
if($argc == 2) |
| 41 |
{ |
| 42 |
$file = NULL; |
| 43 |
$format = $argv[1]; |
| 44 |
} |
| 45 |
else |
| 46 |
{ |
| 47 |
$file = $argv[1]; |
| 48 |
$format = $argv[2]; |
| 49 |
} |
| 50 |
|
| 51 |
if(! array_key_exists($format, $exports)) |
| 52 |
{ |
| 53 |
$msg = ($argv[0] . ": unknown format `" . $format . "'\n" . |
| 54 |
"please use one of:\n"); |
| 55 |
foreach($exports as $format => $name) |
| 56 |
$msg .= " \"" . $name . "\" (" . $format . ")\n"; |
| 57 |
die($msg); |
| 58 |
} |
| 59 |
|
| 60 |
if($file) |
| 61 |
{ |
| 62 |
$cv = caca_create_canvas(0, 0); |
| 63 |
if(caca_import_file($cv, $file, "") < 0) |
| 64 |
{ |
| 65 |
die($argv[0] . ": `" . $file . "' has unknown format\n"); |
| 66 |
} |
| 67 |
} |
| 68 |
else |
| 69 |
{ |
| 70 |
$cv = caca_create_canvas(WIDTH, HEIGHT); |
| 71 |
|
| 72 |
for($y = 0; $y < 256; $y++) |
| 73 |
{ |
| 74 |
for($x = 0; $x < 256; $x++) |
| 75 |
{ |
| 76 |
$r = $x; |
| 77 |
$g = (255 - $y + $x) / 2; |
| 78 |
$b = $y * (255 - $x) / 256; |
| 79 |
imagesetpixel($pixels, $x, $y, imagecolorallocate($pixels, $r, $g, $b)); |
| 80 |
} |
| 81 |
} |
| 82 |
|
| 83 |
$dither = caca_create_dither($pixels); |
| 84 |
if(($format == "ansi") || ($format == "utf8")) |
| 85 |
caca_set_dither_charset($dither, "shades"); |
| 86 |
caca_dither_bitmap($cv, 0, 0, caca_get_canvas_width($cv), |
| 87 |
caca_get_canvas_height($cv), $dither, $pixels); |
| 88 |
|
| 89 |
caca_set_color_ansi($cv, CACA_WHITE, CACA_BLACK); |
| 90 |
caca_draw_thin_box($cv, 0, 0, WIDTH - 1, HEIGHT - 1); |
| 91 |
|
| 92 |
caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE); |
| 93 |
caca_fill_ellipse($cv, WIDTH / 2, HEIGHT / 2, |
| 94 |
WIDTH / 4, HEIGHT / 4, ord(' ')); |
| 95 |
|
| 96 |
caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK); |
| 97 |
caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 6, |
| 98 |
" lightgray on black "); |
| 99 |
caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT); |
| 100 |
caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 5, |
| 101 |
" default on transparent "); |
| 102 |
caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE); |
| 103 |
caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 4, |
| 104 |
" black on white "); |
| 105 |
|
| 106 |
caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE); |
| 107 |
caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]"); |
| 108 |
caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]"); |
| 109 |
caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); |
| 110 |
caca_put_str($cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>"); |
| 111 |
|
| 112 |
caca_set_attr($cv, CACA_BOLD); |
| 113 |
caca_put_str($cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold"); |
| 114 |
caca_set_attr($cv, CACA_BLINK); |
| 115 |
caca_put_str($cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink"); |
| 116 |
caca_set_attr($cv, CACA_ITALICS); |
| 117 |
caca_put_str($cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics"); |
| 118 |
caca_set_attr($cv, CACA_UNDERLINE); |
| 119 |
caca_put_str($cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline"); |
| 120 |
caca_set_attr($cv, 0); |
| 121 |
|
| 122 |
caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE); |
| 123 |
caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); |
| 124 |
|
| 125 |
for($x = 0; $x < 16; $x++) |
| 126 |
{ |
| 127 |
caca_set_color_argb($cv, 0xff00 | $x, 0xf00f | ($x << 4)); |
| 128 |
caca_put_char($cv, WIDTH / 2 - 7 + $x, HEIGHT / 2 + 6, ord('#')); |
| 129 |
} |
| 130 |
} |
| 131 |
|
| 132 |
echo caca_export_string($cv, $format); |
| 133 |
|
| 134 |
?> |