• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1102
  • Last Modified:

Curve Text Dynamicaly

Can somone tell me how to curve text dynamically either using imagemagic or GD  in PHP?
Is it possible. And if not, is there some other tools that will allow me to do that dyamically in php?

Thanks
0
basara55
Asked:
basara55
  • 6
  • 2
  • 2
  • +3
1 Solution
 
rama_krishna580Commented:
0
 
basara55Author Commented:
But is it possible to do it in ImageMagik ? and how ?
0
 
techtonikCommented:
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
basara55Author Commented:
Thats is close but does not curve the text nicely.  What i need is more like curving the text along the path , For example to curve the text in the shape of a circle.

Which means that each of the letters of the text have to rotate at the matching angle.

Anyone knows how to do this ?
0
 
AlievCommented:
Why you need curve.You can take any ttf font. And use it.
Copy yourfont.ttf file to server to same folder with your acript and write these to file:

<?php
  header("Content-type: image/jpeg");
  $im = imagecreate(400,30);
  $white = imagecolorallocate($im, 255,255,255);
  $black = imagecolorallocate($im, 0,0,0);
 
  // Replace path by your own font path
  imagettftext($im, 20, 0, 10, 20, $black, "yourfont.ttf",
  "Testing... Omega: &amp;#937;");
  imagejpeg($im);
  imagedestroy($im);
?>
0
 
basara55Author Commented:
Once again I need a script that will "Bend" or " Curve" or "arc" the text in either GD or Imagemagic.

I know how to write the text in imagemagic and gd , But how do you curve it.

I begining to think that only solution is to write my own function that will use some major Math Trigonometry.
0
 
Marcus BointonCommented:
I get where you're coming from. Like text on a path in Illustrator/Photoshop. The title of the feature in there is how it works too. Here's an example that uses SVG:

http://www.4guysfromrolla.com/demos/svgRender.asp

you could use this and render it server-side somehow in order to give an image usable in GD etc.

Otherwise I think you will need to do the math, as you say. You can place rotated characters in GD (jpGraph does it nicely, with anti-aliasing too), so the "difficult" part is done! You need to define a path, work out the path gradient at a given point, place the center of the char's baseline on it, rotated to match the path angle. You will also need to adjust char spacing for it to look right. I've found this example, which is in Java, but covers the kind of stuff you might need, includes text on curves, and looks quite cool:

http://www.glyphic.com/transform/

You might also find some of the links here useful:

http://www.programming-x.com/programming/curve.html

Sorry I don't have a quick answer (I don't think there is one), but I hope this helps.
0
 
basara55Author Commented:
thanks for your links i will go thru them , How do you save a svg to fiel on server on php ?
0
 
Marcus BointonCommented:
That's what I meant about the "somehow"! You need a server-side SVG renderer. Not sure if one exists specifically - there are probably some Java applets for rendering SVG, and they could probably be run server-side.
I'd love to have a server-side HTML renderer for soem things I do, but I've never seen one of those done either. Would be great to have somethign like Gecko, AppleWebKit (Safari) or IE as a PHP extension...
0
 
basara55Author Commented:
Thanks for your input , i'll wait few more days to see if anyone else has any other ideas or solutions .. and then i will award the points

0
 
petoskey-001Commented:
Hi.  No links.  I tend to take things as challenges.  Here is working code for circles text.

It does a basic round text layout.  This is the simplest case.  Circles are easy, arcs are more difficult, generic splines/bezier harder.  Start with the imageline() function.  Make the lines look the way you want the text to go.

Some things to remember is that ImageTTFText uses degrees, but cos and sin expect radians.  This requires the GD library, TTF support and a font file 'arial.ttf'.

You can see a working example at http://ryba.net/demos/curved-text/

<?php
// ERROR_REPORTING(E_ALL);

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;
        $BX = $cx - cos(deg2rad(360 / $length * $x)) * $cr * 2;
        $BY = $cy - sin(deg2rad(360 / $length * $x)) * $cr * 2;
        //imageline($im, $AX, $AY, $BX, $BY, $color);
        imagettftext($im, 20, -($degDelta * $x + $degDelta / 2)+90 , $AX, $AY, $color, 'arial.ttf', $text[$x]);

    }
}

imagepng($im);
imagedestroy($im);

?>


0
 
basara55Author Commented:
Great work petoeskey , Thats exactly what I needed.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 2
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now