#! /usr/bin/perl # text_to_png.pl - Convert a text file into a png format image # James M. Lynes, Jr. - January 15, 2015 # Proof of concept. File names hard coded. Expand to read command line arguments # or move to Wx gui app. # Tab expansion regex from The Perl Cookbook use strict; use warnings; use GD; open INFILE, "<", "text_to_png.pl" || die; my $image = GD::Image->new(700, 700) || die; my $white = $image->colorAllocate(230,230,230); # background color - Lt Gray my $black = $image->colorAllocate(0,0,0); # text color - Black my $x = 5; my $y = 0; while() { chomp; 1 while s/\t+/' ' x (($+[0] - $-[0]) * 8 - $-[0] % 8)/e; # do tab expansion regex here $image->string(gdMediumBoldFont, $x, $y, $_, $black); $y += 14; } my $png_data = $image->png; open OUTFILE, ">", "text_to_image.png" || die; binmode OUTFILE; print OUTFILE $png_data; close OUTFILE;