I just coded a little very spartanic php script using image-gd library. It read's a text from textarea formular and assigns colors to the characters using there ASCII-Value and some multiplier functions to make color differences between near-neighborhood-ASCII like "a" and "b" visible. At now it's just working for known text size.
<?php
if(isset($_POST['text'])){
//in my case known size of text is 204*204, add your own size here:
asciiToPng(204,204,$_POST['text']);
}else{
$out = "<form name ='textform' action='' method='post'>";
$out .= "<textarea type='textarea' cols='100' rows='100' name='text' value='' placeholder='Asciitext here'></textarea><br/>";
$out .= "<input type='submit' name='submit' value='create image'>";
$out .= "</form>";
echo $out;
}
function asciiToPng($image_width, $image_height, $text)
{
// first: lets type cast;
$image_width = (integer)$image_width;
$image_height = (integer)$image_height;
$text = (string)$text;
// create a image
$image = imagecreatetruecolor($image_width, $image_height);
$black = imagecolorallocate($image, 0, 0, 0);
$x = 0;
$y = 0;
for ($i = 0; $i < strlen($text)-1; $i++) {
//assign some more or less random colors, math functions are just to make a visible difference e.g. between "a" and "b"
$r = pow(ord($text{$i}),4) % 255;
$g = pow(ord($text{$i}),3) % 255;
$b = ord($text{$i})*2 % 255;
$color = ImageColorAllocate($image, $r, $g, $b);
//assign random color or predefined color to special chars ans draw pixel
if($text{$i}!='#'){
imagesetpixel($image, $x, $y, $color);
}else{
imagesetpixel($image, $x, $y, $black);
}
$x++;
if($text{$i}=="\n"){
$x = 0;
$y++;
}
}
// show image, free memory
header('Content-type: image/png');
ImagePNG($image);
imagedestroy($image);
}
?>