back

Kinta.pl

This was a variation of tink.pl and instead of creating coloured text, it created 'greyscale' html text from an image. Like kint.pl it takes the rgb value, only this time it converts it to a greyscale value and then modulo divides it to get it my ascii greyscale palette. This version outputs plain ascii text.

usage: perl kinta.pl image
(output will need to be redirected to a file)
#!/usr/bin/perl

# this version just outputs straight ascii - have deleted all the html and debug code.  see kint.pl for that.

use GD;

$imagefilename = $ARGV[0];

$greydata = q(@XS8O&*;:-,. );

$greylength = length $greydata;

$segment = int (255 / $greylength);

$imagedata = GD::Image->new($imagefilename);

($width , $height) = $imagedata->getBounds();

for ( $y = 0 ; $y < $height ; $y++ ) {
	for ( $x = 0; $x < $width ; $x++ ) {
		( $r ,$g , $b ) = $imagedata->rgb( $imagedata->getPixel( $x , $y ) );

		$greycolour = int (($r + $g + $g) / 3);

		$greyref = int ($greycolour / $segment);
		if ($greyref > $greylength) { $greyref = $greylength;}
		$greyref--;
		$greyout = substr ( $greydata, $greyref , 1);
		print $greyout;
	}
	print "\n";
}

All this code is © 2006 - 2015, except for the noted pieces which are © to their authors as noted. Feel free to use anything you find here, I'm not that precious about it. Take it, improve it, make lots of cash with it, it's a gift.

back