Jump to content

Recommended Posts

Hi Guys,

 

Some help here would be most appreciated.

 

What im basically trying to do is create an image like a postmark stamp where the text curves around the inside of the circle. This text is dynamically generated and will basically be a persons name.

 

So I need a circle with the persons name curving inside the circle edge at the top.

 

I have attached a image of a postmark just incase anyone isnt sure what i mean.

 

[/img]

 

If anyone could help it would be great.

 

Regards,

 

Jon

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/221044-need-to-write-text-in-a-circle/
Share on other sites

Those codes don't work, try them.

 

But the one below does, replace the font with your own font and location.

 

<?php

$text = "- Phpfreaks - QuickOldCar";
$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));

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),200+$xt,200+$yt,$red,"font.TTF",$text[$i]);

}

header("Content-type: image/jpeg");
imagejpeg($image,"",100);
imagedestroy($image);

?>

 

text-in-circle.jpeg

If you want just a name with arc on top change the $degrees and then the $a values for length of your text to look right.

 

<?php

$text = "QuickOldCar";
$image = imagecreatetruecolor(400,400);
$white = imagecolorallocate($image,255,255,255);
imagefill($image,0,0,$white);
$red = imagecolorallocate($image,255,0,0);
$degrees = (180/strlen($text));

for ($i=0;$i<strlen($text);$i++) {
$a = ($degrees*$i)+95;
$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),200+$xt,200+$yt,$red,"font.TTF",$text[$i]);

}

header("Content-type: image/jpeg");
imagejpeg($image,"",100);
imagedestroy($image);

?>

 

text-in-circle(2).jpeg

I didn't notice you said within a circle also, so here is for that.

 

<?php

$text = "QuickOldCar";
$image = imagecreatetruecolor(400,400);
$white = imagecolorallocate($image,255,255,255);
imagefill($image,0,0,$white);
$red = imagecolorallocate($image,255,0,0);
$degrees = (180/strlen($text));
$black = imagecolorallocate($image, 0, 0, 0); 
imagearc($image, 200, 200, 390, 390, 0, 360, $black); 
for ($i=0;$i<strlen($text);$i++) {
$a = ($degrees*$i)+95;
$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,12,180-($a),200+$xt,200+$yt,$red,"font.TTF",$text[$i]);

}

header("Content-type: image/jpeg");
imagejpeg($image,"",80);
imagedestroy($image);

?>

 

text-in-circle(3).jpeg

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.