[1mdiff --git a/textart b/textart[m
[1mnew file mode 100755[m
[1mindex 0000000..c7815a5[m
[1m--- /dev/null[m
[1m+++ b/textart[m
[36m@@ -0,0 +1,337 @@[m
[32m+[m[32m#!/usr/bin/php -q[m
[32m+[m[32m<?php[m
[32m+[m
[32m+[m[32m/**[m
[32m+[m[32m * textart-cli[m
[32m+[m[32m * Version 0.2[m
[32m+[m[32m *[m
[32m+[m[32m * This is free and unencumbered software released into the public domain.[m
[32m+[m[32m *[m
[32m+[m[32m * Anyone is free to copy, modify, publish, use, compile, sell, or distribute[m
[32m+[m[32m * this software, in any form, for any purpose, commercial or non-commercial,[m
[32m+[m[32m * and by any means.[m
[32m+[m[32m *[m[41m [m
[32m+[m[32m * If you require more legalese in your software than this, it means you live[m
[32m+[m[32m * in a retarded clown country and you should probably do something about that.[m
[32m+[m[32m */[m
[32m+[m
[32m+[m[32m$version = "textart-cli version 0.2";[m
[32m+[m
[32m+[m[32mif(!isset($argv[3])) {[m
[32m+[m[32m echo <<<EOL[m
[32m+[m[32m$version[m
[32m+[m
[32m+[m[32mUsage: textart [<max columns][m
[32m+[m
[32m+[m[32m[m
[32m+[m[32m 5color : Five shades of gray rectangles[m
[32m+[m[32m 5colorsq : Five shades of gray squares[m
[32m+[m[32m braille : 2x4 Braille matrix[m
[32m+[m[32m 1x2block : 1x2 Unicode blocks[m
[32m+[m[32m 2x2block : 2x2 Unicode blocks[m
[32m+[m[32m 2x3block : 2x3 Unicode blocks[m
[32m+[m
[32m+[m[32mEOL;[m
[32m+[m[32m die;[m
[32m+[m[32m}[m
[32m+[m
[32m+[m[32m// Default maximum columns[m
[32m+[m[32m$maxcol = 100;[m
[32m+[m
[32m+[m[32m// Supported text art formats[m
[32m+[m[32m$formats = array("5color", "5colorsq", "braille", "1x2block", "2x2block", "2x3block");[m
[32m+[m
[32m+[m[32m// 5color art palettes[m
[32m+[m[32m$rec = array("█", "▓", "▒", "░", " ");[m
[32m+[m[32m$squ = array("██", "▓▓", "▒▒", "░░", " ");[m
[32m+[m
[32m+[m[32m// Block art elements[m
[32m+[m[32m$blk1x2 = array(" ", "▀", "▄", "█");[m
[32m+[m[32m$blk2x2 = array(" ", "▘", "▖", "▌", "▝", "▀", "▞", "▛", "▗", "▚", "▄", "▙", "▐", "▜", "▟", "█");[m
[32m+[m[32m$blk2x3 = array(" ", "🬀", "🬃", "🬄", "🬏", "🬐", "🬓", "▌", "🬁", "🬂", "🬅", "🬆", "🬑", "🬒", "🬔", "🬕",[m
[32m+[m[32m "🬇", "🬈", "🬋", "🬌", "🬖", "🬗", "🬚", "🬛", "🬉", "🬊", "🬍", "🬎", "🬘", "🬙", "🬜", "🬝",[m
[32m+[m[32m "🬞", "🬟", "🬢", "🬣", "🬭", "🬮", "🬱", "🬲", "🬠", "🬡", "🬤", "🬥", "🬯", "🬰", "🬳", "🬴",[m
[32m+[m[32m "🬦", "🬧", "🬩", "🬪", "🬵", "🬶", "🬹", "🬺", "▐", "🬨", "🬫", "🬬", "🬷", "🬸", "🬻", "█"[m
[32m+[m[32m );[m
[32m+[m
[32m+[m[32m// Process input[m
[32m+[m[32m$format = $argv[1];[m
[32m+[m[32m$img = $argv[2];[m
[32m+[m[32m$out = $argv[3];[m
[32m+[m[32mif(isset($argv[4]) && is_numeric($argv[4]))[m
[32m+[m[32m $maxcol = $argv[4];[m
[32m+[m[32melseif(isset($argv[4]))[m
[32m+[m[32m fatal_error("Max columns is not numeric");[m
[32m+[m
[32m+[m[32m// Validate format[m
[32m+[m[32mif(!in_array($format, $formats))[m
[32m+[m[32m fatal_error("Invalid format '$format"");[m
[32m+[m
[32m+[m[32m// Create temp file and download file to it[m
[32m+[m[32m$tmp = tempnam("", "textart");[m
[32m+[m[32mif($tmp === false)[m
[32m+[m[32m fatal_error("Failed to create temp file");[m
[32m+[m[32mcopy($img, $tmp);[m
[32m+[m
[32m+[m[32m// Preprocess image to the target colorspace[m
[32m+[m[32mlist($w, $h) = getimagesize($tmp);[m
[32m+[m
[32m+[m[32mswitch($format) {[m
[32m+[m
[32m+[m[32m // 5colorsq : Five shades of gray squares[m
[32m+[m[32m case "5colorsq":[m
[32m+[m[32m // Preprocess image with ImageMagick[m
[32m+[m[32m $t_2 = tempnam("", "textart2") . ".png";[m
[32m+[m[32m $scale = "";[m
[32m+[m[32m // Scale to fix max columns if greater[m
[32m+[m[32m if($w > ($maxcol/2))[m
[32m+[m[32m $scale = "-scale ".($maxcol/2)."x";[m
[32m+[m[32m // Reduce to 4-bit gray[m
[32m+[m[32m exec("convert $scale -type Grayscale -depth 4 $tmp $t_2");[m
[32m+[m[32m rename($t_2, $tmp);[m
[32m+[m[32m unset($t_2);[m
[32m+[m[41m [m
[32m+[m[32m // Pull image to GD[m
[32m+[m[32m $im = import_grayscale($tmp);[m
[32m+[m
[32m+[m[32m // Step through image from top left to bottom right writing gray shades[m
[32m+[m[32m $o = "";[m
[32m+[m[32m for($y=0; $y<imagesy($im); $y++) {[m
[32m+[m[32m for($x=0; $x<imagesx($im); $x++) {[m
[32m+[m[32m $pix = imagecolorat($im, $x, $y) & 0xff;[m
[32m+[m[32m // Reduce value from 255 to 5 shades[m
[32m+[m[32m if($pix == 0) $pix++;[m
[32m+[m[32m $o .= $squ[(ceil($pix / 0x33) - 1)];[m
[32m+[m[32m }[m
[32m+[m[32m $o .= "\n";[m
[32m+[m[32m }[m
[32m+[m[32m break;[m
[32m+[m
[32m+[m[32m // 5color : Five shades of gray rectangles[m
[32m+[m[32m case "5color":[m
[32m+[m[32m // Preprocess image with ImageMagick[m
[32m+[m[32m // Scale to fix max columns if greater[m
[32m+[m[32m if($w > $maxcol) {[m
[32m+[m[32m $t_2 = tempnam("", "textart2") . ".png";[m
[32m+[m[32m exec("convert -scale ".$maxcol."x $tmp $t_2");[m
[32m+[m[32m rename($t_2, $tmp);[m
[32m+[m[32m unset($t_2);[m
[32m+[m[32m }[m
[32m+[m[32m // Reduce vertical size 50% to suit rectangular pixels[m
[32m+[m[32m $t_3 = tempnam("", "textart3") . ".png";[m
[32m+[m[32m exec("convert -scale 100%x50% -type Grayscale -depth 4 $tmp $t_3");[m
[32m+[m[32m rename($t_3, $tmp);[m
[32m+[m[32m unset($t_3);[m
[32m+[m
[32m+[m[32m // Pull image to GD[m
[32m+[m[32m $im = import_grayscale($tmp);[m
[32m+[m
[32m+[m[32m // Step through image from top left to bottom right writing gray shades[m
[32m+[m[32m $o = "";[m
[32m+[m[32m for($y=0; $y<imagesy($im); $y++) {[m
[32m+[m[32m for($x=0; $x<imagesx($im); $x++) {[m
[32m+[m[32m $pix = imagecolorat($im, $x, $y) & 0xff;[m
[32m+[m[32m // Reduce value from 255 to 5 shades[m
[32m+[m[32m if($pix == 0) $pix++;[m
[32m+[m[32m $o .= $rec[(ceil($pix / 0x33) - 1)];[m
[32m+[m[32m }[m
[32m+[m[32m $o .= "\n";[m
[32m+[m[32m }[m
[32m+[m[32m break;[m
[32m+[m[41m [m
[32m+[m[32m case "braille":[m
[32m+[m[32m // Preprocess image with ImageMagick[m
[32m+[m[32m $t_2 = tempnam("", "textart2") . ".png";[m
[32m+[m[32m $scale = "";[m
[32m+[m[32m // Scale to fix max columns if greater[m
[32m+[m[32m if($w > ($maxcol*2))[m
[32m+[m[32m $scale = "-scale ".($maxcol*2)."x";[m
[32m+[m[32m exec("convert $scale -monochrome $tmp $t_2");[m
[32m+[m[32m rename($t_2, $tmp);[m
[32m+[m[32m unset($t_2);[m
[32m+[m
[32m+[m[32m // Pull image to GD, padding with blank space to nearest Braille tile[m
[32m+[m[32m $im = pad_image(import_grayscale($tmp), 2, 4);[m
[32m+[m
[32m+[m[32m // Step through image from top left to bottom right writing Braille tiles[m
[32m+[m[32m $o = "";[m
[32m+[m[32m for($y=0; $y<imagesy($im); $y=$y+4) {[m
[32m+[m[32m for($x=0; $x<imagesx($im); $x=$x+2) {[m
[32m+[m[32m $o .= chr(0x28) . chr(get_braille_tile($im, $x, $y));[m
[32m+[m[32m }[m
[32m+[m[32m $o .= "\0\n";[m
[32m+[m[32m }[m
[32m+[m[32m // Convert UTF-16 to UTF-8[m
[32m+[m[32m $o = iconv('UTF-16BE', 'UTF-8', $o);[m
[32m+[m[32m break;[m
[32m+[m[41m [m
[32m+[m[32m case "1x2block":[m
[32m+[m[32m // Preprocess image with ImageMagick[m
[32m+[m[32m $t_2 = tempnam("", "textart2") . ".png";[m
[32m+[m[32m $scale = "";[m
[32m+[m[32m // Scale to fix max columns if greater[m
[32m+[m[32m if($w > ($maxcol))[m
[32m+[m[32m $scale = "-scale ".($maxcol)."x";[m
[32m+[m[32m exec("convert $scale -monochrome $tmp $t_2");[m
[32m+[m[32m rename($t_2, $tmp);[m
[32m+[m[32m unset($t_2);[m
[32m+[m
[32m+[m[32m // Pull image to GD, padding with blank space to nearest Braille tile[m
[32m+[m[32m $im = pad_image(import_grayscale($tmp), 1, 2);[m
[32m+[m
[32m+[m[32m // Step through image from top left to bottom right writing Braille tiles[m
[32m+[m[32m $o = "";[m
[32m+[m[32m for($y=0; $y<imagesy($im); $y=$y+2) {[m
[32m+[m[32m for($x=0; $x<imagesx($im); $x=$x+1) {[m
[32m+[m[32m $o .= $blk1x2[get_1x2_tile($im, $x, $y)];[m
[32m+[m[32m }[m
[32m+[m[32m $o .= "\n";[m
[32m+[m[32m }[m
[32m+[m[32m break;[m
[32m+[m[41m [m
[32m+[m[32m case "2x2block":[m
[32m+[m[32m // Preprocess image with ImageMagick[m
[32m+[m[32m // Scale to fix max columns if greater[m
[32m+[m[32m if($w > ($maxcol*2)) {[m
[32m+[m[32m $t_2 = tempnam("", "textart2") . ".png";[m
[32m+[m[32m exec("convert -scale ".($maxcol*2)."x $tmp $t_2");[m
[32m+[m[32m rename($t_2, $tmp);[m
[32m+[m[32m unset($t_2);[m
[32m+[m[32m }[m
[32m+[m[32m // Reduce vertical size 50% to suit rectangular pixels[m
[32m+[m[32m $t_3 = tempnam("", "textart3") . ".png";[m
[32m+[m[32m exec("convert -scale 100%x50% -monochrome $tmp $t_3");[m
[32m+[m[32m rename($t_3, $tmp);[m
[32m+[m[32m unset($t_3);[m
[32m+[m
[32m+[m[32m // Pull image to GD, padding with blank space to nearest Braille tile[m
[32m+[m[32m $im = pad_image(import_grayscale($tmp), 2, 2);[m
[32m+[m
[32m+[m[32m // Step through image from top left to bottom right writing Braille tiles[m
[32m+[m[32m $o = "";[m
[32m+[m[32m for($y=0; $y<imagesy($im); $y=$y+2) {[m
[32m+[m[32m for($x=0; $x<imagesx($im); $x=$x+2) {[m
[32m+[m[32m $o .= $blk2x2[get_2x2_tile($im, $x, $y)];[m
[32m+[m[32m }[m
[32m+[m[32m $o .= "\n";[m
[32m+[m[32m }[m
[32m+[m[32m break;[m
[32m+[m[41m [m
[32m+[m[32m case "2x3block":[m
[32m+[m[32m // Preprocess image with ImageMagick[m
[32m+[m[32m // Scale to fix max columns if greater[m
[32m+[m[32m if($w > ($maxcol*2)) {[m
[32m+[m[32m $t_2 = tempnam("", "textart2") . ".png";[m
[32m+[m[32m exec("convert -scale ".($maxcol*2)."x $tmp $t_2");[m
[32m+[m[32m rename($t_2, $tmp);[m
[32m+[m[32m unset($t_2);[m
[32m+[m[32m }[m
[32m+[m[32m // Reduce vertical size 50% to suit rectangular pixels[m
[32m+[m[32m $t_3 = tempnam("", "textart3") . ".png";[m
[32m+[m[32m exec("convert -scale 100%x80% -monochrome $tmp $t_3");[m
[32m+[m[32m rename($t_3, $tmp);[m
[32m+[m[32m unset($t_3);[m
[32m+[m
[32m+[m[32m // Pull image to GD, padding with blank space to nearest Braille tile[m
[32m+[m[32m $im = pad_image(import_grayscale($tmp), 2, 3);[m
[32m+[m
[32m+[m[32m // Step through image from top left to bottom right writing Braille tiles[m
[32m+[m[32m $o = "";[m
[32m+[m[32m for($y=0; $y<imagesy($im); $y=$y+3) {[m
[32m+[m[32m for($x=0; $x<imagesx($im); $x=$x+2) {[m
[32m+[m[32m $o .= $blk2x3[get_2x3_tile($im, $x, $y)];[m
[32m+[m[32m }[m
[32m+[m[32m $o .= "\n";[m
[32m+[m[32m }[m
[32m+[m[32m break;[m
[32m+[m
[32m+[m[32m}[m
[32m+[m
[32m+[m[32mfile_put_contents($out, $o);[m
[32m+[m
[32m+[m[32munlink($tmp);[m
[32m+[m
[32m+[m[32mprint "$version\nMode: $format\n$o";[m
[32m+[m
[32m+[m[32m// Do fatal error[m
[32m+[m[32mfunction fatal_error($msg) {[m
[32m+[m[32m print "Fatal Error: $msg\n";[m
[32m+[m[32m die;[m
[32m+[m[32m}[m
[32m+[m
[32m+[m[32m// Convert 2x4 pixel area to braille[m
[32m+[m[32mfunction get_braille_tile($im, $x, $y) {[m
[32m+[m[32m return(bindec([m
[32m+[m[32m pixel(imagecolorat($im, $x+1, $y+3)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x, $y+3)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x+1, $y+2)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x+1, $y+1)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x+1, $y)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x, $y+2)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x, $y+1)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x, $y))[m
[32m+[m[32m ));[m
[32m+[m[32m}[m
[32m+[m
[32m+[m[32m// Convert 1x2 pixel area to block[m
[32m+[m[32mfunction get_1x2_tile($im, $x, $y) {[m
[32m+[m[32m return(bindec([m
[32m+[m[32m pixel(imagecolorat($im, $x, $y+1)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x, $y))[m
[32m+[m[32m ));[m
[32m+[m[32m}[m
[32m+[m
[32m+[m[32m// Convert 2x2 pixel area to block[m
[32m+[m[32mfunction get_2x2_tile($im, $x, $y) {[m
[32m+[m[32m return(bindec([m
[32m+[m[32m pixel(imagecolorat($im, $x+1, $y+1)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x+1, $y)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x, $y+1)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x, $y))[m
[32m+[m[32m ));[m
[32m+[m[32m}[m
[32m+[m
[32m+[m[32m// Convert 2x3 pixel area to block[m
[32m+[m[32mfunction get_2x3_tile($im, $x, $y) {[m
[32m+[m[32m return(bindec([m
[32m+[m[32m pixel(imagecolorat($im, $x+1, $y+2)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x+1, $y+1)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x+1, $y)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x, $y+2)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x, $y+1)) .[m
[32m+[m[32m pixel(imagecolorat($im, $x, $y))[m
[32m+[m[32m ));[m
[32m+[m[32m}[m
[32m+[m
[32m+[m[32m// Return ON/OFF state using 0x80 as midpoint[m
[32m+[m[32mfunction pixel($color) {[m
[32m+[m[32m if(($color & 0xff) < 0x80)[m
[32m+[m[32m return(1);[m
[32m+[m[32m else[m
[32m+[m[32m return(0);[m
[32m+[m[32m}[m
[32m+[m
[32m+[m[32mfunction import_grayscale($file) {[m
[32m+[m[32m // Convert input to truecolor and then grayscale[m
[32m+[m[32m $im = @imagecreatefrompng($file);[m
[32m+[m[32m if(!imageistruecolor($im)) {[m
[32m+[m[32m imagepalettetotruecolor($im);[m
[32m+[m[32m }[m
[32m+[m[32m imagefilter($im, IMG_FILTER_GRAYSCALE);[m
[32m+[m[32m return($im);[m
[32m+[m[32m}[m
[32m+[m
[32m+[m[32m// Pad image to size needed for clean conversion[m
[32m+[m[32mfunction pad_image($im, $col, $row) {[m
[32m+[m[32m $t_w = ceil(imagesx($im)/$col) * $col;[m
[32m+[m[32m $t_h = ceil(imagesy($im)/$row) * $row;[m
[32m+[m
[32m+[m[32m $temp = imagecreatetruecolor($t_w, $t_h);[m
[32m+[m[32m $white = imagecolorallocate($temp, 255, 255, 255);[m
[32m+[m[32m imagefill($temp, 0, 0, $white);[m
[32m+[m
[32m+[m[32m imagecopy($temp, $im, 0, 0, 0, 0, imagesx($im), imagesy($im));[m
[32m+[m[32m return($temp);[m
[32m+[m[32m}[m
[32m+[m
[32m+[m[32m?>[m
\ No newline at end of file[m
text/plain
This content has been proxied by September (ba2dc).