Imager::Font::FT2#

📦 std

FreeType 2 fonts for Imager: TrueType, OpenType, Type 1 and the other outline and bitmap formats FreeType reads.

Imager::Font->new(file => ...) picks this driver on its own when the FreeType library is installed; type => 'ft2' asks for it by name. Text is drawn with $img->string, measured with $font->bounding_box, and may be transformed ($font->transform(matrix => ...)), laid out vertically for fonts that carry vertical metrics, and drawn into a single channel with channel =>.

use Imager;

my $font = Imager::Font->new(file => 'DejaVuSans.ttf', size => 24)
    or die Imager->errstr;
$img->string(font => $font, text => 'Hello', x => 10, y => 40,
             color => 'black', aa => 1);

The FreeType library (libfreetype.so.6) is loaded when the module is; without it require Imager::Font::FT2 fails and Imager reports the ft2 format as unavailable, as a perl5 Imager built without FreeType does.

Drawing into a paletted image with a colour that is not in its palette goes through Imager::Font::FT2 exactly as it does in perl5: the image becomes a direct RGB image. This is a native implementation of Imager::Font::FT2 1.005; its .pm is used unchanged.

Differences from upstream#

i_ft2_version(0), the version FreeType had when Imager was compiled, reports the version of the library actually loaded, because nothing here is compiled against FreeType.