Imagefilledellipse Positioning

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
Pineriver
Forum Commoner
Posts: 50
Joined: Fri Aug 15, 2003 5:24 pm

Imagefilledellipse Positioning

Post by Pineriver »

Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Heya!

I have drawn a simple circle with imagefilledellipse by the code below

Code: Select all

$image = imagecreatetruecolor(300, 300);
$ColorArea = imagecolorallocate($image, 0, 0, 255);

$XCenter=150;
$YCenter=150;
$Width=200;
$Height=200;

imageellipse($image, $XCenter, $YCenter, $Width, $Height, $ColorArea);
header("Content-type: image/png");
imagepng($image);;
Which is all good and well, but now I am attempting to draw text from imagesting() along the circle path.
I am not very good in math and PHP, so thought I might ask here.
Somehow needing to convert the curved width and height into placeable pixels for the imagesting() where I can adjust where the text should go from something like $TextPos=70; and where 70 is there is where the text would be placed on the circle from the top.
Any Nibbles?


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Not sure how to help you on this.. but are you refering to something similar to viewtopic.php?t=41557 ?
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Post by jayshields »

/me shouts ONIOOOOOOOOONNNNNN
Pineriver
Forum Commoner
Posts: 50
Joined: Fri Aug 15, 2003 5:24 pm

Yes

Post by Pineriver »

Yes, Ty. Played around with the code a bit and looks like it will get me started.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

jayshields wrote:/me shouts ONIOOOOOOOOONNNNNN
lol..

I'm afraid that, at the moment, I don't have any code that will make text follow a general ellipse.. the best I can offer is text that follows a circle.

Code: Select all

<?php

	$text = "Around and around around and around and around ";
	
	$image = imagecreatetruecolor(400,400);
	$white = imagecolorallocate($image,255,255,255);
	imagefill($image,0,0,$white);
	$red = imagecolorallocate($image,255,0,0);

	$degrees = (360/strlen($text));
	
	$x_offset = 200;
	$y_offset = 200;

	for ($i=0;$i<strlen($text);$i++) {

		$a = ($degrees*$i)+180;

		$cos = cos(deg2rad($a));
		$sin = sin(deg2rad($a));
		$x = 0;
		$y = 180;
		$xt = round($cos*($x) - $sin*($y));
		$yt = round($sin*($x) + $cos*($y));
		imagettftext($image,20,180-($a),$x_offset+$xt,$y_offset+$yt,$red,"fonts/AIRSTREA.TTF",$text[$i]);
		
	}
	
	header("Content-type: image/jpeg");
	imagejpeg($image,"",100);
	imagedestroy($image);
	
?>
$x_offset and $y_offset are the position of the centre of the circle. $y is the radius of the circle. If you want to go around in an oval instead you'll need to modify the value of $y as you progress around the loop based on a trig function .. as it's half past midnight here at the moment I'm not going to figure it out right now.
Image
Post Reply