Textart [master]

Merge version 0.2

=> 9c53bd28a8ba5e54e07e4e286904d168c1b04789

diff --git a/textart b/textart
new file mode 100755
index 0000000..c7815a5
--- /dev/null
+++ b/textart
@@ -0,0 +1,337 @@
+#!/usr/bin/php -q
+   [
+  5color   : Five shades of gray rectangles
+  5colorsq : Five shades of gray squares
+  braille  : 2x4 Braille matrix
+  1x2block : 1x2 Unicode blocks
+  2x2block : 2x2 Unicode blocks
+  2x3block : 2x3 Unicode blocks
+
+EOL;
+  die;
+}
+
+// Default maximum columns
+$maxcol = 100;
+
+// Supported text art formats
+$formats = array("5color", "5colorsq", "braille", "1x2block", "2x2block", "2x3block");
+
+// 5color art palettes
+$rec = array("█", "▓", "▒", "░", " ");
+$squ = array("██", "▓▓", "▒▒", "░░", "  ");
+
+// Block art elements
+$blk1x2 = array(" ", "▀", "▄", "█");
+$blk2x2 = array(" ", "▘", "▖", "▌", "▝", "▀", "▞", "▛", "▗", "▚", "▄", "▙", "▐", "▜", "▟", "█");
+$blk2x3 = array(" ", "🬀", "🬃", "🬄", "🬏", "🬐", "🬓", "▌", "🬁", "🬂", "🬅", "🬆", "🬑", "🬒", "🬔", "🬕",
+                "🬇", "🬈", "🬋", "🬌", "🬖", "🬗", "🬚", "🬛", "🬉", "🬊", "🬍", "🬎", "🬘", "🬙", "🬜", "🬝",
+                "🬞", "🬟", "🬢", "🬣", "🬭", "🬮", "🬱", "🬲", "🬠", "🬡", "🬤", "🬥", "🬯", "🬰", "🬳", "🬴",
+                "🬦", "🬧", "🬩", "🬪", "🬵", "🬶", "🬹", "🬺", "▐", "🬨", "🬫", "🬬", "🬷", "🬸", "🬻", "█"
+               );
+
+// Process input
+$format = $argv[1];
+$img    = $argv[2];
+$out    = $argv[3];
+if(isset($argv[4]) && is_numeric($argv[4]))
+  $maxcol = $argv[4];
+elseif(isset($argv[4]))
+  fatal_error("Max columns is not numeric");
+
+// Validate format
+if(!in_array($format, $formats))
+  fatal_error("Invalid format \'$format\"");
+
+// Create temp file and download file to it
+$tmp = tempnam("", "textart");
+if($tmp === false)
+  fatal_error("Failed to create temp file");
+copy($img, $tmp);
+
+// Preprocess image to the target colorspace
+list($w, $h) = getimagesize($tmp);
+
+switch($format) {
+
+  // 5colorsq : Five shades of gray squares
+  case "5colorsq":
+    // Preprocess image with ImageMagick
+    $t_2 = tempnam("", "textart2") . ".png";
+    $scale = "";
+    // Scale to fix max columns if greater
+    if($w > ($maxcol/2))
+      $scale = "-scale ".($maxcol/2)."x";
+    // Reduce to 4-bit gray
+    exec("convert $scale -type Grayscale -depth 4 $tmp $t_2");
+    rename($t_2, $tmp);
+    unset($t_2);
+    
+    // Pull image to GD
+    $im = import_grayscale($tmp);
+
+    // Step through image from top left to bottom right writing gray shades
+    $o = "";
+    for($y=0; $y $maxcol) {
+      $t_2 = tempnam("", "textart2") . ".png";
+      exec("convert -scale ".$maxcol."x $tmp $t_2");
+      rename($t_2, $tmp);
+      unset($t_2);
+    }
+    // Reduce vertical size 50% to suit rectangular pixels
+    $t_3 = tempnam("", "textart3") . ".png";
+    exec("convert -scale 100%x50% -type Grayscale -depth 4 $tmp $t_3");
+    rename($t_3, $tmp);
+    unset($t_3);
+
+    // Pull image to GD
+    $im = import_grayscale($tmp);
+
+    // Step through image from top left to bottom right writing gray shades
+    $o = "";
+    for($y=0; $y ($maxcol*2))
+      $scale = "-scale ".($maxcol*2)."x";
+    exec("convert $scale -monochrome $tmp $t_2");
+    rename($t_2, $tmp);
+    unset($t_2);
+
+    // Pull image to GD, padding with blank space to nearest Braille tile
+    $im = pad_image(import_grayscale($tmp), 2, 4);
+
+    // Step through image from top left to bottom right writing Braille tiles
+    $o = "";
+    for($y=0; $y ($maxcol))
+      $scale = "-scale ".($maxcol)."x";
+    exec("convert $scale -monochrome $tmp $t_2");
+    rename($t_2, $tmp);
+    unset($t_2);
+
+    // Pull image to GD, padding with blank space to nearest Braille tile
+    $im = pad_image(import_grayscale($tmp), 1, 2);
+
+    // Step through image from top left to bottom right writing Braille tiles
+    $o = "";
+    for($y=0; $y ($maxcol*2)) {
+      $t_2 = tempnam("", "textart2") . ".png";
+      exec("convert -scale ".($maxcol*2)."x $tmp $t_2");
+      rename($t_2, $tmp);
+      unset($t_2);
+    }
+    // Reduce vertical size 50% to suit rectangular pixels
+    $t_3 = tempnam("", "textart3") . ".png";
+    exec("convert -scale 100%x50% -monochrome $tmp $t_3");
+    rename($t_3, $tmp);
+    unset($t_3);
+
+    // Pull image to GD, padding with blank space to nearest Braille tile
+    $im = pad_image(import_grayscale($tmp), 2, 2);
+
+    // Step through image from top left to bottom right writing Braille tiles
+    $o = "";
+    for($y=0; $y ($maxcol*2)) {
+      $t_2 = tempnam("", "textart2") . ".png";
+      exec("convert -scale ".($maxcol*2)."x $tmp $t_2");
+      rename($t_2, $tmp);
+      unset($t_2);
+    }
+    // Reduce vertical size 50% to suit rectangular pixels
+    $t_3 = tempnam("", "textart3") . ".png";
+    exec("convert -scale 100%x80% -monochrome $tmp $t_3");
+    rename($t_3, $tmp);
+    unset($t_3);
+
+    // Pull image to GD, padding with blank space to nearest Braille tile
+    $im = pad_image(import_grayscale($tmp), 2, 3);
+
+    // Step through image from top left to bottom right writing Braille tiles
+    $o = "";
+    for($y=0; $y
\ No newline at end of file
Proxy Information
Original URL
gemini://git.brainsocks.xyz/textart/master/cdiff/9c53bd28a8ba5e54e07e4e286904d168c1b04789
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
734.219521 milliseconds
Gemini-to-HTML Time
0.741343 milliseconds

This content has been proxied by September (ba2dc).