From 9c53bd28a8ba5e54e07e4e286904d168c1b04789 Mon Sep 17 00:00:00 2001
From: Anonymous anonymous@zokni.xyz
Date: Thu, 11 Apr 2024 16:07:24 -0400
Subject: [PATCH 1/1] Merge version 0.2
textart | 337 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 337 insertions(+)
create mode 100755 textart
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
+/**
+$version = "textart-cli version 0.2";
+if(!isset($argv[3])) {
+$version
+Usage: textart [<max columns]
+
+EOL;
+}
+// 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]))
+elseif(isset($argv[4]))
+// Validate format
+if(!in_array($format, $formats))
+// Create temp file and download file to it
+$tmp = tempnam("", "textart");
+if($tmp === false)
+copy($img, $tmp);
+// Preprocess image to the target colorspace
+list($w, $h) = getimagesize($tmp);
+switch($format) {
$scale = "-scale ".($maxcol/2)."x";
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";
$t_2 = tempnam("", "textart2") . ".png";
exec("convert -scale ".$maxcol."x $tmp $t_2");
rename($t_2, $tmp);
unset($t_2);
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";
$scale = "-scale ".($maxcol*2)."x";
for($x=0; $x<imagesx($im); $x=$x+2) {
$o .= chr(0x28) . chr(get_braille_tile($im, $x, $y));
}
$o .= "\0\n";
$scale = "-scale ".($maxcol)."x";
for($x=0; $x<imagesx($im); $x=$x+1) {
$o .= $blk1x2[get_1x2_tile($im, $x, $y)];
}
$o .= "\n";
$t_2 = tempnam("", "textart2") . ".png";
exec("convert -scale ".($maxcol*2)."x $tmp $t_2");
rename($t_2, $tmp);
unset($t_2);
for($x=0; $x<imagesx($im); $x=$x+2) {
$o .= $blk2x2[get_2x2_tile($im, $x, $y)];
}
$o .= "\n";
$t_2 = tempnam("", "textart2") . ".png";
exec("convert -scale ".($maxcol*2)."x $tmp $t_2");
rename($t_2, $tmp);
unset($t_2);
for($x=0; $x<imagesx($im); $x=$x+2) {
$o .= $blk2x3[get_2x3_tile($im, $x, $y)];
}
$o .= "\n";
+}
+file_put_contents($out, $o);
+unlink($tmp);
+print "$version\nMode: $format\n$o";
+// Do fatal error
+function fatal_error($msg) {
+}
+// Convert 2x4 pixel area to braille
+function get_braille_tile($im, $x, $y) {
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) {
pixel(imagecolorat($im, $x, $y+1)) .
pixel(imagecolorat($im, $x, $y))
));
+}
+// Convert 2x2 pixel area to block
+function get_2x2_tile($im, $x, $y) {
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) {
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) {
+}
+function import_grayscale($file) {
+}
+// Pad image to size needed for clean conversion
+function pad_image($im, $col, $row) {
+}
+?>
\ No newline at end of file
--
2.34.1
text/plain
This content has been proxied by September (3851b).