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

+<?php

+

+/**

+ * textart-cli

+ * Version 0.2

+ *

+ * This is free and unencumbered software released into the public domain.

+ *

+ * Anyone is free to copy, modify, publish, use, compile, sell, or distribute

+ * this software, in any form, for any purpose, commercial or non-commercial,

+ * and by any means.

+ * 

+ * If you require more legalese in your software than this, it means you live

+ * in a retarded clown country and you should probably do something about that.

+ */

+

+$version = "textart-cli version 0.2";

+

+if(!isset($argv[3])) {

+ echo <<<EOL

+$version

+

+Usage: textart [<max columns]

+

+

+ 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<imagesy($im); $y++) {

+ for($x=0; $x<imagesx($im); $x++) {

+ $pix = imagecolorat($im, $x, $y) & 0xff;

+ // Reduce value from 255 to 5 shades

+ if($pix == 0) $pix++;

+ $o .= $squ[(ceil($pix / 0x33) - 1)];

+ }

+ $o .= "\n";

+ }

+ break;

+

+ // 5color : Five shades of gray rectangles

+ case "5color":

+ // Preprocess image with ImageMagick

+ // Scale to fix max columns if greater

+ if($w > $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<imagesy($im); $y++) {

+ for($x=0; $x<imagesx($im); $x++) {

+ $pix = imagecolorat($im, $x, $y) & 0xff;

+ // Reduce value from 255 to 5 shades

+ if($pix == 0) $pix++;

+ $o .= $rec[(ceil($pix / 0x33) - 1)];

+ }

+ $o .= "\n";

+ }

+ break;

+ 

+ case "braille":

+ // 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";

+ 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<imagesy($im); $y=$y+4) {

+ for($x=0; $x<imagesx($im); $x=$x+2) {

+ $o .= chr(0x28) . chr(get_braille_tile($im, $x, $y));

+ }

+ $o .= "\0\n";

+ }

+ // Convert UTF-16 to UTF-8

+ $o = iconv('UTF-16BE', 'UTF-8', $o);

+ break;

+ 

+ case "1x2block":

+ // Preprocess image with ImageMagick

+ $t_2 = tempnam("", "textart2") . ".png";

+ $scale = "";

+ // Scale to fix max columns if greater

+ if($w > ($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<imagesy($im); $y=$y+2) {

+ for($x=0; $x<imagesx($im); $x=$x+1) {

+ $o .= $blk1x2[get_1x2_tile($im, $x, $y)];

+ }

+ $o .= "\n";

+ }

+ break;

+ 

+ case "2x2block":

+ // Preprocess image with ImageMagick

+ // Scale to fix max columns if greater

+ if($w > ($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<imagesy($im); $y=$y+2) {

+ for($x=0; $x<imagesx($im); $x=$x+2) {

+ $o .= $blk2x2[get_2x2_tile($im, $x, $y)];

+ }

+ $o .= "\n";

+ }

+ break;

+ 

+ case "2x3block":

+ // Preprocess image with ImageMagick

+ // Scale to fix max columns if greater

+ if($w > ($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<imagesy($im); $y=$y+3) {

+ for($x=0; $x<imagesx($im); $x=$x+2) {

+ $o .= $blk2x3[get_2x3_tile($im, $x, $y)];

+ }

+ $o .= "\n";

+ }

+ break;

+

+}

+

+file_put_contents($out, $o);

+

+unlink($tmp);

+

+print "$version\nMode: $format\n$o";

+

+// Do fatal error

+function fatal_error($msg) {

+ print "Fatal Error: $msg\n";

+ die;

+}

+

+// Convert 2x4 pixel area to braille

+function get_braille_tile($im, $x, $y) {

+ return(bindec(

+ pixel(imagecolorat($im, $x+1, $y+3)) .

+ pixel(imagecolorat($im, $x, $y+3)) .

+ pixel(imagecolorat($im, $x+1, $y+2)) .

+ pixel(imagecolorat($im, $x+1, $y+1)) .

+ pixel(imagecolorat($im, $x+1, $y)) .

+ pixel(imagecolorat($im, $x, $y+2)) .

+ pixel(imagecolorat($im, $x, $y+1)) .

+ pixel(imagecolorat($im, $x, $y))

+ ));

+}

+

+// Convert 1x2 pixel area to block

+function get_1x2_tile($im, $x, $y) {

+ return(bindec(

+ pixel(imagecolorat($im, $x, $y+1)) .

+ pixel(imagecolorat($im, $x, $y))

+ ));

+}

+

+// Convert 2x2 pixel area to block

+function get_2x2_tile($im, $x, $y) {

+ return(bindec(

+ pixel(imagecolorat($im, $x+1, $y+1)) .

+ pixel(imagecolorat($im, $x+1, $y)) .

+ pixel(imagecolorat($im, $x, $y+1)) .

+ pixel(imagecolorat($im, $x, $y))

+ ));

+}

+

+// Convert 2x3 pixel area to block

+function get_2x3_tile($im, $x, $y) {

+ return(bindec(

+ pixel(imagecolorat($im, $x+1, $y+2)) .

+ pixel(imagecolorat($im, $x+1, $y+1)) .

+ pixel(imagecolorat($im, $x+1, $y)) .

+ pixel(imagecolorat($im, $x, $y+2)) .

+ pixel(imagecolorat($im, $x, $y+1)) .

+ pixel(imagecolorat($im, $x, $y))

+ ));

+}

+

+// Return ON/OFF state using 0x80 as midpoint

+function pixel($color) {

+ if(($color & 0xff) < 0x80)

+ return(1);

+ else

+ return(0);

+}

+

+function import_grayscale($file) {

+ // Convert input to truecolor and then grayscale

+ $im = @imagecreatefrompng($file);

+ if(!imageistruecolor($im)) {

+ imagepalettetotruecolor($im);

+ }

+ imagefilter($im, IMG_FILTER_GRAYSCALE);

+ return($im);

+}

+

+// Pad image to size needed for clean conversion

+function pad_image($im, $col, $row) {

+ $t_w = ceil(imagesx($im)/$col) * $col;

+ $t_h = ceil(imagesy($im)/$row) * $row;

+

+ $temp = imagecreatetruecolor($t_w, $t_h);

+ $white = imagecolorallocate($temp, 255, 255, 255);

+ imagefill($temp, 0, 0, $white);

+

+ imagecopy($temp, $im, 0, 0, 0, 0, imagesx($im), imagesy($im));

+ return($temp);

+}

+

+?>

\ No newline at end of file

Proxy Information
Original URL
gemini://git.brainsocks.xyz/textart/master/pcdiff/9c53bd28a8ba5e54e07e4e286904d168c1b04789
Status Code
Success (20)
Meta
text/plain
Capsule Response Time
776.312097 milliseconds
Gemini-to-HTML Time
7.293043 milliseconds

This content has been proxied by September (ba2dc).