Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 1 of 1
  1. #1
    hgs
    hgs is offline
    New Coder
    Join Date
    Jan 2010
    Location
    Germany
    Posts
    83
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Vertical text with PHP

    Hello all

    Below is a short simple script that generates an image with the given text in vertical direction.

    A demo and a zip file with the needed font files can be found
    at www.hgsweb.de

    Usage singel line : <img src="gdstringup.php?text=vertical text">
    Usage multiple line : <img src="gdstringup.php?text=vertical<br>text<br>line">

    PHP Code:
    <?php
    //////////////////////////////////////////////////////////////////////
    //
    // Developed by Heinz Schweitzer
    // ASSUMPTION: hardcoded character cell width of 8 and a hight of 12
    // change to your needs
    //////////////////////////////////////////////////////////////////////
    header ("Content-type: image/gif"); 
    $s=$_GET["text"];
    if(
    strlen($s)==0){
        
    $s="Missing Text!";
    }
    $el=explode("<br>",$s);
    $nel=count($el);
    if(
    $nel>0){
        for(
    $i=0,$imghigh=0;$i<$nel;$i++){    
            
    $high=strlen($el[$i])*8+2;
            if(
    $high>$imghigh){
                
    $imghigh=$high;
            }
        }
    } else {
        
    $imghigh=strlen($s)*8+2;
    }
    if(
    $nel==1){
        
    $imgwidth=12;
    }else{
        
    $imgwidth=12+($nel*14);
    }
    $im imagecreatetruecolor($imgwidth$imghigh)or die('Cannot Initialize new GD image stream');
    $black imagecolorallocate($im000);
    imagecolortransparent($im$black);
    $text_color imagecolorallocate($im,1010,10);
    $font=imageloadfont("courier-bold.gdf");
    $py=imagefontwidth($font);
    for(
    $i=0,$x=0;$i<$nel;$i++){
        
    $l=strlen($el[$i]);    
        
    imagestringup($im,$font $x$imghigh,  $el[$i], $text_color);
        
    $x+=14;
    }
    imagegif($im);
    imagedestroy($im);
    ?>
    Regards
    Heinz
    Last edited by hgs; 01-19-2010 at 01:35 PM. Reason: changed tags


 

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •