I have successfully written text to my img
and positioned it correctly, however the problem I have ran into is that increasing the font size makes the text go off the image.
So I know I can achieve the look I want by just simply increasing the line height of the text writing to the screen. I can't seem to find any documentation on if/how this can be done.
My php code
<?php
$font = 'font-type.ttf';
$rImg = ImageCreateFromJPEG( "test.jpg" );
$color = imagecolorallocate($rImg, 255, 255, 255);
//create bounding box
$bbox = imagettfbbox ( 38 , 0 , $font , urldecode($_GET['promo']) );
//setting the cordinates
$x = $bbox[0] + (imagesx($rImg) / 2) - ($bbox[4] / 2) + 200;
$y = $bbox[1] + (imagesy($rImg) / 2) - ($bbox[5] / 2) + 25;
//write it
imagettftext($rImg, 38, 0, $x, $y, $color, $font, urldecode($_GET['promo']));
header('Content-type: image/jpeg');
imagejpeg($rImg, NULL,100);
imagedestroy($rImg);
?>
I have achieved my desired look using this function
function ImageTTFTextWithTracking($im, $size, $angle, $t, $x, $y, $color, $font, $text) {
$numchar = strlen($text);
for($i = 0; $i < $numchar; $i++) {
# Assign character
$char[$i] = substr($text, $i, 1);
# Write character
imagettftext($im, $size, $angle, ($x + $w + ($i * $t)), $y, $color, $font, $char[$i]);
# Get width of character
$width = imagettfbbox($size, $angle, $font, $char[$i]);
$w = $w + $width[2];
}
}
ImageTTFTextWithTracking($rImg, 48, 0, 10, $x, $y, $colorWhite, $font, urldecode($_GET['code']));