I'm trying to load an image and recreate it using text. I just made an img2ascii/html/text converter and I just have to do the other way around, for no particular reason.
But... The image is not displaying correctly. Mainly a dark rectangle, with a not so dark rectangle inside it. Below some code for you amusement. My first thought is that a char (here: ·) actually is larger than a pixel, but I'm getting hardly any colour output at all.
Not really sure this is a way to create an image...
Not to fond of image conversions, but if someone have input please do let me know.
Code: Select all
$cfg['ImagePath'] = './images/fav.jpg'; // img to use
$image = @imagecreatefromjpeg($cfg['ImagePath']);
$image = resizeimage($image, $cfg['Ascii']['Width']); // user function, depending on GD version
$xmax = imagesx($image);
$ymax = imagesy($image);
$im = imagecreate($xmax, $ymax); // the new image
$bcol = imagecolorallocate($im, 90, 90, 90);
imagecolortransparent($im, $bcol);
$font = imageloadfont('font.gdf'); // own bitmapfont
for ($y = 0; $y < $ymax; $y++) { // loop original image Y
for ($x = 0; $x < $xmax; $x++) { // loop original image X
$colindex = imagecolorat($image, $x, $y); // get index
$colrgb = imagecolorsforindex($image, $colindex); // get rgb
$col = imagecolorallocate($im, $colrgb['red'], $colrgb['green'], $colrgb['blue']); // get color from rgb
// the $x & $y here is a big questionmark.
imagestring($im, $font, $x, $y, '·', $col); // output
}
}