#!/usr/bin/perl use warnings; use File::Temp qw(tempfile); use List::Util qw(max min); $font = 'FreeMono'; # Approximate dimensions used to determine approximate size. Only the # value that produces the higher resolution (for the given input) is used. $desired_width = 1296; $desired_height = 1296; # Font size in points (72 points per inch). This does not determine the size of # the image, because the image density is defined in terms of it. # Probably this should be changed so density is fixed and font size varies. $font_size = 72; $margin = $font_size; $width_chars = 0; $height_lines = 0; ### ($tempFH, $tempFN) = tempfile(); for () { $width_chars = max((length $_), $width_chars); ++$height_lines; print $tempFH $_; } $PPI = 72; # points per inch sub choose_density() { my $width_density = $PPI * $desired_width / $width_chars / $font_size; my $height_density = $PPI * $desired_height / $height_lines / $font_size; return max($width_density, $height_density); } $density = choose_density; $character_size = $font_size * $density / $PPI; $initial_image_size = sprintf "%ix%i", 1.25 * $character_size * $width_chars, 1.25 * $character_size * $height_lines; $offset = sprintf '+%i+%i', ($character_size) x 2; $output = 'png:-'; system <