How to write the text inside the circle

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crajesh
Forum Newbie
Posts: 1
Joined: Mon Jun 28, 2010 1:11 am

How to write the text inside the circle

Post by crajesh »

Hi all,

I am new in Php GD. I need to create the circle, inside the circle i need to write the text. how to do this? please help me?

I have create the circle. but i am not able to write the text inside the circle. How to write the text inside the circle.

This is my code

Code: Select all

<?php
create_image();
?>

<table>
<tr>
<td> <?php print "<img src=image.png?".date("U").">"; ?> </td>
<td> <?php print "<img src=image.png?".date("U").">"; ?> </td>
</tr>
</table>

<?php
function  create_image(){
        $im = @imagecreate(600, 200) or die("Cannot Initialize new GD image stream");
        $background_color = imagecolorallocate($im, 255, 255, 255);  
        $red = imagecolorallocate($im, 255, 0, 0);            
        imageellipse($im, 50, 50, 40, 60, $red);
        imageline ($im,65,56,78,78,$blue); 
        imagepng($im,"image.png");
        imagedestroy($im);
}
?>

Thanks
C.Rajesh
Last edited by Benjamin on Mon Jun 28, 2010 6:12 am, edited 1 time in total.
Reason: Added [syntax=php] tags.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: How to write the text inside the circle

Post by Benjamin »

:arrow: Moved to PHP - Code
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: How to write the text inside the circle

Post by McInfo »

crajesh wrote:How to write the text inside the circle.
Are you asking how to draw arced text like might be found along the circumference of a coin, or straight text that fits within the area of the circle/ellipse?

PHP's GD library does not have a function to draw arced text (that I know of), but imagettftext() and imagepstext() both have an angle parameter to allow you to draw text at a particular angle. If you read up on calculus, you can write a function to calculate the slope of a line tangent to an ellipse at a particular point and convert the slope to an angle. For circles, a tangent line is perpendicular to a radial line at the same point. Draw letters individually at different points on the ellipse with the appropriate angles. For letters placed within the ellipse (rather than on the outer circumference), base your calculations on a smaller ellipse.
pollock
Forum Newbie
Posts: 9
Joined: Tue Jun 29, 2010 7:23 am

Re: How to write the text inside the circle

Post by pollock »

crajesh wrote:Hi all,

I am new in Php GD. I need to create the circle, inside the circle i need to write the text. how to do this? please help me?

I have create the circle. but i am not able to write the text inside the circle. How to write the text inside the circle.

This is my code

Code: Select all

<?php
create_image();
?>

<table>
<tr>
<td> <?php print "<img src=image.png?".date("U").">"; ?> </td>
<td> <?php print "<img src=image.png?".date("U").">"; ?> </td>
</tr>
</table>

<?php
function  create_image(){
        $im = @imagecreate(600, 200) or die("Cannot Initialize new GD image stream");
        $background_color = imagecolorallocate($im, 255, 255, 255);  
        $red = imagecolorallocate($im, 255, 0, 0);            
        imageellipse($im, 50, 50, 40, 60, $red);
        imageline ($im,65,56,78,78,$blue); 
        imagepng($im,"image.png");
        imagedestroy($im);
}
?>

Thanks
C.Rajesh



you will go through this link http://www.hypergurl.com/insidecircle.html here given a php tutorial and explain step by step how to write the text inside the circle.

Warm regards
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: How to write the text inside the circle

Post by McInfo »

pollock wrote:you will go through this link http://www.hypergurl.com/insidecircle.html here given a php tutorial and explain step by step how to write the text inside the circle.
That tutorial is for PSP (Paint Shop Pro), not PHP.
sunny82
Forum Newbie
Posts: 1
Joined: Thu Nov 11, 2010 9:41 am

Re: How to write the text inside the circle

Post by sunny82 »

Here is the function name "gdImageStringFTCircle" from GD version 2.0.33 that puts text in circular way in image http://www.boutell.com/gd/manual2.0.33. ... ngFTCircle

Thanks
S
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: How to write the text inside the circle

Post by McInfo »

sunny82 wrote:gdImageStringFTCircle
That is a C function that is not implemented in PHP's GD library.
Post Reply