Solved

Curve Text Dynamicaly

Posted on 2004-04-29
13
1,079 Views
Last Modified: 2012-06-21
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
Comment
Question by:basara55
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 2
  • 2
  • +3
13 Comments
 
LVL 23

Expert Comment

by:rama_krishna580
ID: 10950718
0
 

Author Comment

by:basara55
ID: 10952228
But is it possible to do it in ImageMagik ? and how ?
0
 
LVL 9

Expert Comment

by:techtonik
ID: 10955111
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Expert Comment

by:techtonik
ID: 10955125
0
 

Author Comment

by:basara55
ID: 10955249
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
 
LVL 3

Expert Comment

by:Aliev
ID: 10957124
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
 

Author Comment

by:basara55
ID: 10958637
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
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 10960057
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
 

Author Comment

by:basara55
ID: 10961154
thanks for your links i will go thru them , How do you save a svg to fiel on server on php ?
0
 
LVL 25

Expert Comment

by:Marcus Bointon
ID: 10961393
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
 

Author Comment

by:basara55
ID: 10963069
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
 
LVL 7

Accepted Solution

by:
petoskey-001 earned 500 total points
ID: 10965838
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
 

Author Comment

by:basara55
ID: 10967116
Great work petoeskey , Thats exactly what I needed.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

731 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question