Re: Text on a curve with GD
From: Idris (mohd_idris_khan_at_hotmail.com)
Date: 12/03/04
- Previous message: Design-Crowd: "Freelancers required"
- In reply to: Oli Filth: "Re: Text on a curve with GD"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 3 Dec 2004 00:05:30 -0000
Thank you. Most kind. Will try this as soon as I've updated my GD
version since it's complaining about imagerotate. Even after the
"make install". Will keep trying though.
"Oli Filth" <oli_filth@eatspam.coldmail.com> wrote in message
news:U5Mrd.1033$gj.449@newsfe2-win.ntli.net...
> Idris wrote:
>> Hi,
>>
>> I'm looking for a GD code snippet for producing text
>> that follows a curve (like numbers on a clock) but the
>> letters must adjust their angle to follow that curve.
>>
>> Any help will be greatly appreciated.
>>
>> Thanks.
>>
>> Idris.
>>
>>
>>
>
> ==== BEGIN PHP CODE ====
>
> <?php
>
> function DrawTextArc($str, $aStart, $aEnd, $iRadius, $bCCW)
> {
> $nFont = 5;
>
> // create image to store each character
> $xFont = imagefontwidth($nFont);
> $yFont = imagefontheight($nFont);
> $imgChar = imagecreatetruecolor($xFont, $yFont);
> // create overall image
> $iCentre = $iRadius + max($xFont, $yFont);
> $img = imagecreatetruecolor(2 * $iCentre, 2 * $iCentre);
> // sort out colours
> $colBG = imagecolorallocate($img, 255, 255, 255);
> $colBGchar = imagecolorallocate($imgChar, 255, 255, 255);
> $colFGchar = imagecolorallocate($imgChar, 0, 0, 0);
> imagefilledrectangle($img, 0, 0, 2 * $iCentre, 2 * $iCentre, $colBG);
>
> // arrange angles depending on direction of rotation
> if ($bCCW)
> {
> while ($aEnd < $aStart)
> {
> $aEnd += 360;
> }
> }
> else
> {
> while ($aEnd > $aStart)
> {
> $aEnd -= 360;
> }
> }
>
> $len = strlen($str);
>
> // draw each character individually
> for ($i = 0; $i < $len; $i++)
> {
> // calculate angle along arc
> $a = ($aStart * ($len - 1 - $i) + $aEnd * $i) / ($len - 1);
>
> // draw individual character
> imagefilledrectangle($imgChar, 0, 0, $xFont, $yFont, $colBGchar);
> imagestring($imgChar, $nFont, 0, 0, $str[$i], $colFGchar);
>
> // rotate character
> $imgTemp = imagerotate($imgChar, (int)$a + 90 * ($bCCW ? 1 : -1),
> $colBGchar);
> $xTemp = imagesx($imgTemp);
> $yTemp = imagesy($imgTemp);
>
> // copy to main image
> imagecopy($img, $imgTemp,
> $iCentre + $iRadius * cos(deg2rad($a)) - ($xTemp / 2),
> $iCentre - $iRadius * sin(deg2rad($a)) - ($yTemp / 2),
> 0, 0, $xTemp, $yTemp);
> }
>
> return $img;
> }
>
>
>
> $img = DrawTextArc("This is the string to display", 135, 300, 200, TRUE);
>
> // output the image
> header("Content-type: image/jpeg");
> imagejpeg($img);
>
> ?>
>
> ===== END PHP CODE =====
>
> Needs quite a bit of work, but you get the idea.
> $str is the text-string, $aStart is the angular position of the first
> character, $aEnd that of the last character (both measured CCW from the
> +ve x-axis), $iRadius is the arc-radius, $bCCW is TRUE or FALSE depending
> on which direction of rotation you want.
>
> Hope this helps,
> Oli
>
- Previous message: Design-Crowd: "Freelancers required"
- In reply to: Oli Filth: "Re: Text on a curve with GD"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|