How to generate adaptive text that bends inside a circle in php?

I am trying to create an image with a circle and text on it, where the text curves around the inside of the circle. The circle is responsive, and I want the text inside it to be adaptive.

So far, I have the following code that generates text that twists:

$row1="line1"; $degrees = (130/strlen($row1)); imageellipse ( $im , 250 , 250 , 390 , 390 , $black ); imageellipse ( $im , 250 , 250 , 398 , 398 , $black ); for ($i=0;$i<strlen($row1);$i++) { $a = ($degrees*$i)+126-strlen($row1)/3; $cos = cos(deg2rad($a)); $sin = sin(deg2rad($a)); $x = 0; $y = 180; $xt = round($cos*($x) - $sin*($y)); $yt = round($sin*($x) + $cos*($y)); imagettftext($im,14,180-($a),250+$xt,270+$yt,$red,'fonts\times.TTF',$row1[$i]); } 

Could you tell me how I can make it adaptive so that it can adapt to the generated ellipse?

+4
source share
1 answer

Hope this helps:

  $image = imagecreatetruecolor(400,400); $white = imagecolorallocate($image,255,255,255); imagefill($image,0,0,$white); $red = imagecolorallocate($image,255,0,0); $degrees = (360/strlen($text)); for($i=0;$i<strlen($text);$i++) { $a = ($degrees*$i)+180; $cos = cos(deg2rad($a)); $sin = sin(deg2rad($a)); $x = 0; $y = 180; $xt = round($cos*($x) - $sin*($y)); $yt = round($sin*($x) + $cos*($y)); imagettftext($image,20,180-($a),200+$xt,200+$yt,$red,"C:/WINNT/Fonts arial.ttf",$text[$i]); } 
0
source

Source: https://habr.com/ru/post/1444660/


All Articles