diff --git a/caca-php/examples/www/export.php b/caca-php/examples/www/export.php old mode 100755 new mode 100644 index 58542db..1a05c67 --- a/caca-php/examples/www/export.php +++ b/caca-php/examples/www/export.php @@ -1,4 +1,3 @@ -#!/usr/bin/php5 3) -{ - $msg = ($argv[0] . ": wrong argument count\n" . - "usage: " . $argv[0] . " [file] \n" . - "where is one of:\n"); - foreach($exports as $format => $name) - $msg .= " \"" . $name . "\" (" . $format . ")\n"; - die($msg); -} - -if($argc == 2) -{ - $file = NULL; - $format = $argv[1]; -} -else -{ - $file = $argv[1]; - $format = $argv[2]; -} +$file = isset($_FILES['file']) ? $_FILES['file']['tmp_name'] : NULL; +$format = isset($_REQUEST['format']) ? $_REQUEST['format'] : NULL; -if(! array_key_exists($format, $exports)) +if((! $format) || (! array_key_exists($format, $exports))) { - $msg = ($argv[0] . ": unknown $format `" . $format . "'\n" . - "please use one of:\n"); - foreach($exports as $format => $name) - $msg .= " \"" . $name . "\" (" . $format . ")\n"; - die($msg); + header("Content-type: text/html; charset=UTF-8"); + +?> + + + +libcaca export test program + + + + +
+ + (optional) +
+ + + +
+ + +<><><> <>--<>]"); - caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]"); - caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); - caca_put_str($cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>"); - - caca_set_attr($cv, CACA_BOLD, CACA_DEFAULT); - caca_put_str($cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold"); - caca_set_attr($cv, CACA_BLINK, CACA_DEFAULT); - caca_put_str($cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink"); - caca_set_attr($cv, CACA_ITALICS, CACA_DEFAULT); - caca_put_str($cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics"); - caca_set_attr($cv, CACA_UNDERLINE, CACA_DEFAULT); - caca_put_str($cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline"); - caca_set_attr($cv, 0, CACA_DEFAULT); - - caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE); - caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); - - for($x = 0; $x < 16; $x++) - { - caca_set_color_argb($cv, 0xff00 | $x, 0xf00f | ($x << 4)); - caca_put_char($cv, WIDTH / 2 - 7 + $x, HEIGHT / 2 + 6, ord('#')); - } + $cv = caca_create_canvas(WIDTH, HEIGHT); + + for($y = 0; $y < 256; $y++) + { + for($x = 0; $x < 256; $x++) + { + $r = $x; + $g = (255 - $y + $x) / 2; + $b = $y * (255 - $x) / 256; + imagesetpixel($pixels, $x, $y, imagecolorallocate($pixels, $r, $g, $b)); + } + } + + $dither = caca_create_dither($pixels); + if(($format == "ansi") || ($format == "utf8")) + caca_set_dither_charset($dither, "shades"); + caca_dither_bitmap($cv, 0, 0, caca_get_canvas_width($cv), + caca_get_canvas_height($cv), $dither, $pixels); + + caca_set_color_ansi($cv, CACA_WHITE, CACA_BLACK); + caca_draw_thin_box($cv, 0, 0, WIDTH - 1, HEIGHT - 1); + + caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE); + caca_fill_ellipse($cv, WIDTH / 2, HEIGHT / 2, + WIDTH / 4, HEIGHT / 4, ord(' ')); + + caca_set_color_ansi($cv, CACA_LIGHTGRAY, CACA_BLACK); + caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 6, + " lightgray on black "); + caca_set_color_ansi($cv, CACA_DEFAULT, CACA_TRANSPARENT); + caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 5, + " default on transparent "); + caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE); + caca_put_str($cv, WIDTH / 2 - 12, HEIGHT / 2 - 4, + " black on white "); + + caca_set_color_ansi($cv, CACA_BLACK, CACA_WHITE); + caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 3, "[<><><><> <>--<>]"); + caca_put_str($cv, WIDTH / 2 - 8, HEIGHT / 2 - 2, "[ドラゴン ボーレ]"); + caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2 + 2, "äβç ░▒▓█▓▒░ ΔЗҒ"); + caca_put_str($cv, WIDTH / 2 - 5, HEIGHT / 2 + 4, "(\") \\o/ <&>"); + + caca_set_attr($cv, CACA_BOLD, CACA_DEFAULT); + caca_put_str($cv, WIDTH / 2 - 16, HEIGHT / 2 + 3, "Bold"); + caca_set_attr($cv, CACA_BLINK, CACA_DEFAULT); + caca_put_str($cv, WIDTH / 2 - 9, HEIGHT / 2 + 3, "Blink"); + caca_set_attr($cv, CACA_ITALICS, CACA_DEFAULT); + caca_put_str($cv, WIDTH / 2 - 1, HEIGHT / 2 + 3, "Italics"); + caca_set_attr($cv, CACA_UNDERLINE, CACA_DEFAULT); + caca_put_str($cv, WIDTH / 2 + 8, HEIGHT / 2 + 3, "Underline"); + caca_set_attr($cv, 0, CACA_DEFAULT); + + caca_set_color_ansi($cv, CACA_WHITE, CACA_LIGHTBLUE); + caca_put_str($cv, WIDTH / 2 - 7, HEIGHT / 2, " LIBCACA "); + + for($x = 0; $x < 16; $x++) + { + caca_set_color_argb($cv, 0xff00 | $x, 0xf00f | ($x << 4)); + caca_put_char($cv, WIDTH / 2 - 7 + $x, HEIGHT / 2 + 6, ord('#')); + } } +$content_type_map = array( + 'ansi' => 'text/plain; charset=CP437', + 'utf8' => 'text/plain; charset=UTF-8', + 'utf8cr' => 'text/plain; charset=UTF-8', + 'html' => 'text/html; charset=UTF-8', + 'html3' => 'text/html; charset=UTF-8', + 'bbfr' => 'text/plain; charset=UTF-8', + 'irc' => 'text/plain; charset=UTF-8', + 'ps' => 'application/postscript', + 'svg' => 'image/svg+xml', + 'tga' => 'image/x-targa' + ); + +$extension_map = array( + 'ansi' => 'txt', + 'tga' => 'tga' + ); + +if (! array_key_exists($format, $content_type_map)) + $content_type = 'application/octet-stream'; +else + $content_type = $content_type_map[$format]; + +header('Content-Type: ' . $content_type); +if (array_key_exists($format, $extension_map)) + header('Content-Disposition: attachment; filename=export.' . $extension_map[$format]); + echo caca_export_string($cv, $format); ?>