Solved

Curve Text Dynamicaly

Posted on 2004-04-29
13
1,064 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
Comment Utility
0
 

Author Comment

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

Expert Comment

by:techtonik
Comment Utility
0
 
LVL 9

Expert Comment

by:techtonik
Comment Utility
0
 

Author Comment

by:basara55
Comment Utility
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
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 

Author Comment

by:basara55
Comment Utility
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:Squinky
Comment Utility
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
Comment Utility
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:Squinky
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Great work petoeskey , Thats exactly what I needed.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now