我有一個巨大的Ascii文本代表像ASCII藝術的位圖。現在我正在尋找一種倒轉的Ascii藝術發電機。我喜歡將每個字符轉換爲彩色像素。 有沒有免費的工具可以像這樣?在位圖中可視化Ascii文本
更新: 我用下面的代碼編碼的小工具,它在不在線:http://www.webspice.eu/ascii2png/
我有一個巨大的Ascii文本代表像ASCII藝術的位圖。現在我正在尋找一種倒轉的Ascii藝術發電機。我喜歡將每個字符轉換爲彩色像素。 有沒有免費的工具可以像這樣?在位圖中可視化Ascii文本
更新: 我用下面的代碼編碼的小工具,它在不在線:http://www.webspice.eu/ascii2png/
我只是編碼一點非常spartanic使用image-gd庫的php腳本。它從textarea公式中讀取文本,並使用Ascii-Value和一些乘數函數爲字符賦予顏色,以使近似鄰域Ascii(如「a」和「b」)之間的顏色差異可見。現在它只是爲已知的文字大小工作。
<?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);
}
?>
您可以在線在這裏找到工作工具:http://www.webspice.eu/ascii2png/
您沒有使用特定的編程語言的標籤。因此,Mathematica去..
我用Rasterize
將一個字母轉換成一個字母的圖像。然後我可以用ImageData
提取像素矩陣。所有像素的Mean
是計算字母的最終像素值的一種可能性。投入,它存儲的像素值,所以我們沒有計算這一遍又一遍的功能如下:
toPixel[c_String] := toPixel[c] = Mean[Flatten[ImageData[Rasterize[
Style[c, 30, FontFamily -> "Courier"], "Image", ColorSpace -> "Grayscale"]]]]
現在,您可以將字符串分割成線,然後應用此每個字符。填充所產生的名單再次得到一個完整的矩陣之後,你有你的形象
data = toPixel /@ Characters[#] & /@ StringSplit[text, "\n"];
[email protected](PadRight[#, 40, 1] & /@ data) // ImageAdjust
對於這個文本
,i!!!!!!;,
.,;i!!!!!'`,uu,o$$bo.
!!!!!!!'.e$$$$$$$$$$$$$$.
!!!!!!! $$$$$$$$$$$$$$$$$P
!!!!!!!,`$$$$$$$$P""`,,`"
i!!!!!!!!,$$$$",oed$$$$$$
!!!!!!!!!'P".,e$$$$$$$$"'?
`!!!!!!!! z$'J$$$$$'.,$bd$b,
`!!!!!!f;$'d$$$$$$$$$$$$$P',c,.
!!!!!! $B,"?$$$$$P',uggg$$$$$P"
!!!!!!.$$$$be."'zd$$$P".,uooe$$r
`!!!',$$$$$$$$$c,"",ud$$$$$$$$$L
!! $$$$$$$$$$$$$$$$$$$$$$$$$$$$$
!'j$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
[email protected]@,?$$$$$$$$$$$$$$$$$$$$$$$$$$$$P
[email protected]@f:$$$$$$$$$$$$$$$$$$$$$$$$$$$'
"" `$$$$$$$$$$$$$$$$$$$$$$$$$$F
`3$$$$$$$$$$$$$$$$$$$$$$F
`"$$$$$P?$$$$$$$"`
`""
我們得到
由於字符是不是你可能需要每個字符轉換成一個矩形像素方格。我一直很想寫這樣的程序多年。 –
只是爲了不讓我誤解:我喜歡爲每個角色只獲取一個像素。這實際上是爲了自己編程,但我敢肯定有人已經完成了它) – abimelex
最難的部分是爲每個角色生成一張顏色表。一旦你完成了,它就是十幾行Python。 –