FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


Make a image with wordwrap





Mgccl
I just wrote some code and tested it. and it runs quite fine. see if this works for you or not.
It create a transparent text box and start writing things on it.
It does not include the angle function yet
Code:

function imagewordwrap($image,$x,$y,$w,$h,$text,$font,$color,$size=10,$dial='-'){
   $cool = imagettfbbox ($size, 0, $font, 'A');
   $line_height = $cool[1]-$cool[7];
   $textarea = imagecreatetruecolor($w,$h);
   $base = imagecreatefromstring(base64_decode('iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29mdHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADqSURBVHjaYvz//z/DYAYAAcTEMMgBQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAgAEAMpcDTTQWJVEAAAAASUVORK5CYII='));
 imagealphablending($textarea,false);
imagesavealpha($textarea,true);
   imagecopyresized($textarea,$base,0,0,0,0,$w,$h,imagesx($base),imagesy($base));
   
   $word = explode(' ',$text);
   $count = count($word);
   $n = 0;
   $tmp ='';
   $real='';
   while($n<$count){
      $a = imagettfbbox($size, 0, $font, $tmp.' '.$word[$n]);
      if($a[2]-$a[0]<=$w){
         $tmp .= $word[$n].' ';
      }else{
         $a = imagettfbbox($size,0,$font, $word[$n]);
         if($a[2] - $a[0]<=$w){
            $real .= $tmp."\n";
            $tmp = $word[$n];
         }else{
            $k = 0;
            $c = strlen($word[$n]);
            while($k<$c){
               $a = imagettfbbox($size, 0, $font, $tmp.' '.$word[$n][$k].$dial);
               if($a[2]-$a[0]<=$w){
                  $tmp .= ' '.$word[$n][$k];
                  
               }else{
                  
                  if($k !=0){
                     $real .= "\n".$tmp.$dial;
                     $tmp = '';
                     
                  }
               }
               ++$k;
            }
         }
      }
      ++$n;
   }
   $real .= $tmp;
   imagettftext($textarea, $size, 0, 0, $line_height, $color, 'C2C_faded.ttf', $real);
   imagecopy($image, $textarea, $x, $y, 0, 0, $w, $h);
}
Confused
chris20
I tried it out a little bit ago. It's pretty interesting.
Would recommend checking it out if you have a chance.
Related topics
Image resizer
Random image for your gallery
Image transparency script
Replace the art and personal pictures with an image gallery?
Can some install Image Magick?
Image Processing in C++ by Shirish
Tutorial: Image Rollovers w/ Javascript
PHP Image Upload (MySQL/Folder)
online / offline image dilemma
How To Make A Mini-Image for safedisc 4
phbb skin
Which image host do you use?
13*13 ico image
First Hour With Longhorn HEC (Image HEAVY)
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.