
Bild nach ASCII
Diese Funktion wandelt ein Bild in ASCII Zeichen um, dabei kann festgelegt werden welches Bild umgewandelt werden soll und welches Zeichen für ein Pixel eingesetzt werden soll.
|
|
<?php
function img_to_ascii($image, $chr) {
$infos = getimagesize($image);
if($infos[2] == 2) {
$img = imagecreatefromjpeg($image);
} elseif($infos[2] == 3) {
$img = imagecreatefrompng($image);
}
for($y=0; $y<$infos[1]; $y++) {
for($x=0; $x<$infos[0]; $x++) {
$col_tmp = imagecolorat($img, $x, $y);
$rgb = imagecolorsforindex($img, $col_tmp);
$str = '<font color="#%02x%02x%02x">'.$chr.
</font>;
printf($str, $rgb['red'],$rgb['green'],
$rgb['blue']);
}
echo '<br>';
}
imagedestroy($img);
}
//Beispiel
img_to_ascii("./bild.png", "o");
?>
|
T: 34979 G: 7 H: 10 T: +4 O: 6
|
|