Jump to content

Trying to arc text on an image layer. GD Liibrary??


bobinindia

Recommended Posts

So here is the code. I want to imagerotate()  each character from imagechar() before it is printed.

Any suggestions?

 

<?php

 

$string = '1 2 3 4 5 6 7 8 9 A B C D E F G';

$font_size = 5;

$width=imagefontwidth($font_size)*strlen($string);

$height=imagefontheight($font_size)*2;

$img = imagecreate($width,$height);

$bg = imagecolorallocate($img,225,225,225);

$black = imagecolorallocate($img,0,0,0);

$len=strlen($string);

$r = 100;

 

for($i=0;$i<$len;$i++)

{

    $xpos=$i*imagefontwidth($font_size);

    $ypos=6;

//somehow rotate in here below

    imagechar($img,$font_size,$xpos,$ypos,$string,$black);

    $string = substr($string,1);

   

   

 

}

header("Content-Type: image/gif");

imagegif($img);

imagedestroy($img);

?>

Link to comment
Share on other sites

Umm.. I think you'll have to improvise on this one. There is no easy way to create arced text as a whole, as such that I know of.. But with imagettftext:

 

imagettftext  ( resource $image  , float $size  , float $angle  , int $x  , int $y  , int $color  , string $fontfile  , string $text  )

 

the third element is float angle, which you can set to face the character facing from 0 to 359 degrees. If you have $string, you can use $str_split($string, 1) to split the string up into one character chunks. Then use imagettftext for all of them, using a slightly different angle for each and a slightly different x and y co-ord. Will give an arced effect, with experimenting.

 

Hope that helps?

 

Sam

Link to comment
Share on other sites

So here is the solution as it must be shared.

Thank you all for your suggestions.

<?php
//This works with GD2 and PHP 5.

    $text = "SAI BABA SAI BABA SAI BABA ";
   
    $image = imagecreatefromjpeg("frontrange.jpeg");
    $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 = 70;
        $xt = round($cos*($x) - $sin*($y));
        $yt = round($sin*($x) + $cos*($y));
        imagettftext($image,20,180-($a),110+$xt,100+$yt,$red,"Fonts/Palatino",$text[$i]);
       
    }
   
    header("Content-type: image/jpeg");
    imagejpeg($image,"",100);
    imagedestroy($image);
   
?>

Link to comment
Share on other sites

  • 2 weeks later...
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.