GD center text on a image

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Krustov

    #1

    GD center text on a image

    The following works fine - but would like to center the text .

    Whats the best way to do it ? .



    <?php

    $text=$kk[4];

    if ($kk[4]=="") {$text="MAIN MENU"; $kk[1]="mainmenu"; }

    $img_name="imag es/zdefault.jpg"; $source=ImageCr eateFromJPEG($i mg_name);

    $white=imagecol orallocate($sou rce,255,255,255 );
    $grey=imagecolo rallocate($sour ce,213,224,225) ;
    $black=imagecol orallocate($sou rce,0,0,0);

    $font='arial.tt f';

    imagettftext($s ource,28,0,12,3 9,$grey, $font, $text);

    imagettftext($s ource,28,0,10,3 7,$black,$font, $text);

    $new_name="cat/$kk[1].jpg";

    ImageJPEG($sour ce,$new_name);

    imagedestroy($s ource);

    ?>

  • Krustov

    #2
    Re: GD center text on a image

    <comp.lang.ph p>
    <Krustov>
    <Fri, 1 Dec 2006 20:34:27 -0000>
    <MPG.1fdaa2333d 32bec98a26b@new s.newsreader.co m>
    Whats the best way to do it ? .
    >
    The below seems to work ok .

    It seems strange that such a common feature like a align L/C/R parimeter
    should be left out of a text function .



    <?php

    $text=$kk[4];

    if ($kk[4]=="") {$text="MAIN MENU"; $kk[1]="mainmenu"; }

    $img_name="imag es/zdefault.jpg"; $source=ImageCr eateFromJPEG($i mg_name);

    $grey=imagecolo rallocate($sour ce,213,224,225) ;
    $black=imagecol orallocate($sou rce,0,0,0);

    $font='arial.tt f';

    $bbox=imagettfb box(28,$angle,$ font,$text);

    $textWidth=$bbo x[2]-$bbox[0];

    $z=$bbox[2]/2;

    $x=320-$z;

    $y=37;

    imagettftext($s ource,28,0,$x+2 ,$y+2,$grey,$fo nt,$text);

    imagettftext($s ource,28,0,$x,$ y,$black,$font, $text);

    $new_name="cat/$kk[1].jpg";

    ImageJPEG($sour ce,$new_name);

    imagedestroy($s ource);

    ?>


    --

    Comment

    Working...