This is not what you might be looking for, but I believe it will help you.
$im = imagecreate(400,400); $txtcol = imagecolorallocate($im, 0xFF, 0xFF, 0x00); $size = 20; $txt = 'DUMMY TEXT'; $font = 'Capriola-Regular.ttf'; /*two points for base line*/ $x1 = 70; $x2 = 170; $y1 = 140; $y2 = 240; /*bof finding line angle*/ $delta_x = $x2-$x1; $delta_y = $y2-$y1; $texangle = (rad2deg(atan2($delta_y,$delta_x)) * 180 / M_PI)-360; /*eof finding the line angle*/ imageline($im,$x1,$y1,$x2,$y2,'0xDD'); //Drawing line imagettftext($im, $size, -45, $x1, $y1-10, '0xDD', $font, $txt); // Drawing text over line at line angle header('Content-Type: image/png'); imagepng($im); imagedestroy($im);
Values
hardcoded. Here the angle is set as -45 and for this angle, if you want the text to appear above the line, you need to reduce the value from the starting position Y of your line. And you have to write code to calculate the angle with the line x1, x2y1, y2
zamil
source share