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
Solved

Curve Text Dynamicaly

Posted on 2004-04-29
13
1,074 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
  • 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
editing example file and creating an accessible same directory error log txt file 2 55
Currency in SQL? 2 30
PHP and JQuery Syntax question 4 26
Help with PHP 13 27
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

839 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