#!/usr/bin/perl # kint.pl - create 'greyscale' ascii images from image files. reads all the formats that the GD module does # (c) d.shaw may/june 2008. # # usage is - # perl kint.pl image fontsize linesize [background-colour] [forground-colour] # # last two are optional and default to white and black respectively # # there's no error checking done either on anything, so it won't throw errors, it'll just fail... use GD; #### setup variables $imagefilename = $ARGV[0]; $fontsize = $ARGV[1]; $linesize = $ARGV[2]; $bgcolour = $ARGV[3]; $fgcolour = $ARGV[4]; if (!$bgcolour ) { $bgcolour = "ffffff";} if (!$fgcolour ) { $fgcolour = "000000";} $greydata = q(@XS8O&*;:-·,. ); $greylength = length $greydata; $segment = int (255 / $greylength); #### load the image and get the width and height from it $imagedata = GD::Image->new($imagefilename); ($width , $height) = $imagedata->getBounds(); #### print the html header print q(
) . "\n";


####	this is the main loop

for ( $y = 0 ; $y < $height ; $y++ ) {
	for ( $x = 0; $x < $width ; $x++ ) {
		( $r ,$g , $b ) = $imagedata->rgb( $imagedata->getPixel( $x , $y ) );		#	this gets the rgb values from the pixel

		$greycolour = int (($r + $g + $g) / 3);										#	and this averages them down to a greyscale value

		$greyref = int ($greycolour / $segment);									#	this next couple of lines figures out which letter to
		if ($greyref > $greylength) { $greyref = $greylength;}						#	to substitute for the greyvalue.  probably could be done
		$greyref--;																	#	better...
		$greyout = substr ( $greydata, $greyref , 1);
		print $greyout;
	}
	print "\n";																		#	'cos we're using 
 we only need a newline not a 
} print q(
);