Hello, I am a first time poster on these forums. Hopefully someone can help me and hopefully I can help others in the future.

I am writing a pretty complicated application using PHP & GD to generate images with text. I need to generate text on a curved path on the fly, something like this:

Curved Up

&
Curved Down

I know that you can create the text at an angle using the function imagettftext, as it is one of the parameters. If you break a string down to its individual characters then adjust the angle and x and y, I'm sure this is possible. I just have no clue how to script it.

Any ideas would be much appreciated. Thanks in advance.

    Sounds to me like you'd have to mess around with sines and cosines and stuff. I'm not good with math, though 🙂

      Yuck... :bemused: I hate trig and stink at it too.

      I guess I'll give it a shot... any other ideas/help people?

        Replies like the two above add nothing towards solving this problem. If you want to bloat your post count without being an utter waste of space then go and play the word association game in the echo lounge.

          Okay, where's your solution, Drakla? At least the two previous posts were actually on the subject of the problem; yours was just gratuitous bitching.

          I suggested some tools (trigonometry) that might be applicable to the problem at hand. Unfortunately, I don't know the subject well enough to provide a complete solution, but I'm not aware of anything in the phpbuilder.com site guidelines that says I can't comment on a help request unless I'm a licensed expert in the subject.

          PHP does, of course, have built-in trigonometric functions.

            imagettftext can generate your desired image, also you will have play with co-ordinates. visit php.net for examples.

              Ok so I've gotten this far.... well actually I found this code somewhere.

              Image sample

              <?php
              
              header("Content-type: image/png");
              $im = imagecreate(400,200);
              $white = imagecolorallocate($im, 255,255,255);
              $black = imagecolorallocate($im, 0,0,0);
              
              $cx = 200;
              $cy = 100;
              $cr = 80;
              if (isset($_REQUEST["text"])) {
                  $text = $_REQUEST["text"];
              } else {
                  $text = 'hello there';
              }
              
              $length = strlen($text);
              $degDelta = 360 / $length;
              if ($length > 0) {
                  $color = $black;
                  for ($x = 0; $x < $length; $x++) {
                      // Circular Text
                      $AX = $cx - cos(deg2rad($degDelta * $x)) * $cr;
                      $AY = $cy - sin(deg2rad($degDelta * $x)) * $cr;
              
                  imagettftext($im, 20, -($degDelta * $x + $degDelta / 2)+90 , $AX, $AY, $color, 'arial.ttf', $text[$x]);
              
              }
              }
              
              imagepng($im);
              imagedestroy($im);
              
              ?>
              

              Almost there... Here is what I need to fix. I don't want the text to be spread out all the way to make a circle. So I want each character next to each other on the circular path. If the string length is long enough so that it goes all the way around the circle that is okay. But I don't want a 5 letter word spread out all around the circle. I'm pretty sure this is possible. I took a stab at it, but completely ruined things. Anyone good at trigonometry?

              I posted something useful. Are you happy Drakla? BTW, thanks for your input it was really helpful.

                7 months later

                Did you succeded calculating the length that will be occupied by the chars displayed? I'm facing the same situation here, even if the way I achieved text curved is a bit "lengthy" 🙂

                  Write a Reply...