2948 explained code solutions for 75 technologies


php-gdHow to change font size


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

$font = '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf';
imagettftext($im, 55, 0, 50, 150, $c_green, $font, 'I am big');
imagettftext($im, 25, 0, 50, 50, $c_green, $font, 'I am small');

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

creates true color GD image object with specified width & height

imagettftext

draw text with given ttf font

$font

path to the font file

55

larger font size

25

smaller font size


How to change font size, php gd

Usage example

<?php

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

$font = '/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf';
imagettftext($im, 50, 0, 50, 150, $c_green, $font, 'I am big');
imagettftext($im, 20, 0, 50, 50, $c_green, $font, 'I am small');

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