use Font::TTFMetrics; my $resolution = 72; # 72dpi typical, 96, 100, 120 common my $pointsize = 12; # Whatever size the target text is my $string = 'Some string'; my $font = Font::TTFMetrics->new('/path/to/Font.ttf'); my $font_units = $font->string_width($string); my $pixels = $font_units * $pointsize * $resolution / (72 * $font->get_units_per_em); printf "Width of `%s' is %.2f font units, or %d pixels\n", $string, $font_units, $pixels;