9951 explained code solutions for 126 technologies


php-gdHow to use freetype font


Before using freetype font, make sure your GD library supports it.

$im = imagecreatetruecolor(400, 300);
$c_green = imageColorAllocate($im, 46,204,64);

$font = '/var/www/sumkin.otf';
imagettftext($im, 40, 0, 100, 100, $c_green, $font, 'Hi!');

imagePng($im, '/tmp/image.png');ctrl + c
$font

path to freetype font file (we used sumkin font for example)

imagettftext

draw text with given ttf font


How to use freetype font, php gd

Usage example

<?php

$im = imagecreatetruecolor(400, 300);
$c_green = imageColorAllocate($im, 46,204,64);

$font = '/var/www/sumkin.otf';
imagettftext($im, 40, 0, 100, 100, $c_green, $font, 'Hi!');

imagePng($im, '/tmp/image.png');