Hello, thanks to everyone in this wonderful forum. You guys rock!

I am looking for a script that allows me to call it from an image tag... Basically img src=scriptname.php?text=$textvar&width=300&fontsize=3

I don't need to get fancy with different fonts for now, the built in one works fine.

I only need it to word wrap at the width (not cutting off words) and make the image the proper height based on the number of lines needed for the text file. It doesn't matter how tall it becomes, as long as the word wrap works properly.

Anyone know of anything like that already written? I've been searching for quite a while and I haven't found anything this simple.

Inputs - text, width (in pixels), font size

Thanks in advance
crazyjeremy

    What I have so far is:

    <?php
    
    $ext="png";
    $headerinfo="Content-type: image/png";
    //Content-type: image/jpeg
    
    if (!isset($s)){$s=1;}else{if ($s<1){$s=1;}if ($s>5){$s=5;}}
    
    if (!isset($c)) {$c="b";}
    
    
    if (file_exists("./cj/$t-$s-$c.$ext"))
    {
           header("$headerinfo");
    
    $fn=fopen("./cj/$t-$s-$c.$ext","r"); 
    fpassthru($fn); 
    
    }
    else
    {
           header("$headerinfo");
    
    $tl=strlen($t);
    
    //image width
    //$iw=$tl*5+4;
    
    $iw=($tl*(4+$s))+4;
    
    //image height
    $ih=((3*$s)+7);
    
    $im = @imagecreate($iw, $ih)
       or die("Cannot Initialize new GD image stream");
    $background_color = imagecolorallocate($im, 255, 255, 255);
    $blackcolor=imagecolorallocate($im, 0, 0, 0);
    $bluecolor=imagecolorallocate($im, 1, 1, 155);
    $yellowcolor=imagecolorallocate($im, 255, 255, 0);
    $redcolor = imagecolorallocate($im, 233, 14, 91);
    
    if ($c=="b") {$text_color=$bluecolor;}
    if ($c=="k") {$text_color=$blackcolor;}
    if ($c=="y") {$text_color=$yellowcolor;}
    if ($c=="r") {$text_color=$redcolor;}
    
    imagestring($im, $s, 1, 1,  $t, $text_color);
    
    //imagepng($im);
    //imagepng($im,"./$t.png");
    
    //imagejpeg($im);
    imagejpeg($im,"./cj/$t-$s-$c.$ext");
    $fn=fopen("./cj/$t-$s-$c.$ext","r"); 
    fpassthru($fn); 
    
    
    imagedestroy($im);
    }
    ?>

    It works wonderfully for what it was originally designed but I know it could probably be much better...

    I just call it with img src=di.php?t=text&c=b&s=1
    t=text obviously, c=color and s=size. I want to add w for width.

    Any ideas how to modify it to do word wrapping and width? I know it would probably be breaking down all the words individually, counting them one by one, dividing them into wordwrappable sized lines... then counting the height and calling the image width and height accordingly...

      Write a Reply...