php - 如何在 php 中生成在圆圈内弯曲的自适应文本?

标签 php

我正在尝试创建一个带有圆圈和一些文本的图像,其中文本围绕圆圈内部弯曲。圆圈是自适应的,我希望它里面的文字是自适应的。

到目前为止,我有以下生成曲线文本的代码:

    $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]);
    }

你能告诉我如何让它自适应,以便它可以适应生成的椭圆吗?

最佳答案

希望对您有所帮助:

     $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]);
        }

关于php - 如何在 php 中生成在圆圈内弯曲的自适应文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13277949/

相关文章:

php - 什么应用程序在 SQL 查询中的 PHP 标签周围插入 html 注释标签?

php - 为什么网站速度会逐渐变慢?

php - 如何在cakephp中调用存储过程?

php - 如何使用 PHP-CLI 获取光标位置?

php - 使用 Twemproxy 安装了 Redis 集群,我真的很困惑为什么某些 SET 命令被 MOVED

php - 使用 php 查找我的扩展类所在的目录

php - 是否可以使用另一个变量来获取 $this ?

php - 如何使用 union all 仅回显一个参数

php - 检测 Paypal 订阅取消

php - codeigniter 内部连接不起作用