Tutorial :How to display vertical text (90 degree rotated) in all browsers?



Question:

How can I display vertical text (90 degree rotated) in all browsers?

alt text http://blogs.sun.com/oootnt/resource/sbres_1164126054_0__.png


Solution:1

The problem is independent from the server side language. If it's not a problem when the vertically rendered text isn't text anymore but an image, choose the solution provided by tharkun. Otherwise, there are ways to do it in the presentation layer.

First, there's (at the moment) an IE-only solution, which is part of the CSS3 standard. You can check it live.

p {      writing-mode: tb-rl;  }  

The CSS3 text module also specify some properties for text orientation.

Other guys do it with SVG.


Solution:2

I don't think you can rotate text with PHP/HTML/CSS. But you can create an image with GD containing vertical text.

Example:

header ("Content-type: image/png");     // imagecreate (x width, y width)  $img_handle = @imagecreatetruecolor (15, 220) or die ("Cannot Create image");     // ImageColorAllocate (image, red, green, blue)  $back_color = ImageColorAllocate ($img_handle, 0, 0, 0);   $txt_color = ImageColorAllocate ($img_handle, 255, 255, 255);   ImageStringUp ($img_handle, 2, 1, 215, $_GET['text'], $txt_color);   ImagePng ($img_handle);   ImageDestroy($img_handle);  


Solution:3

function verticletext($string)      {         $tlen = strlen($string);         for($i=0;$i<$tlen;$i++)         {              $vtext .= substr($string,$i,1)."<br />";            }         return $vtext;      }  

there you go no echo


Solution:4

Text rotation is also possible with other browsers.

CSS:

/*Safari*/  -webkit-transform: rotate(-90deg);    /*Firefox*/  -moz-transform: rotate(-90deg);    /*Opera*/  -o-transform: rotate(-90deg);    /*IE*/  writing-mode: tb-rl;  filter: flipV flipH;  


Solution:5

I use the function below if table header rows are too long. It's quite useful because it's easy to use, fast and you don't have to calculate text height & width. Those css-gimmicks just don't work.

#######################################################  # convert text to image and embed it to html  # uses /tmp as a cache to make it faster  # usage: print imagetext("Hello my friend");  # Created by Ville Jungman, GPL-licenced, donated by www.varuste.net    function imagetext($text,$size = 10,$color = array(253,128,46)){    $dir = "/tmp/tekstit";    $filename = "$dir/" . base64_encode($text);    if(!file_exists($filename)){       $font = "/usr/share/fonts/truetype/freefont/FreeSans.ttf";       $box = imagettfbbox($size,90,$font,$text);       $w = -$box[4] - 1;       $h = -$box[3];       $im = imagecreatetruecolor($w,$h);       $white = imagecolorallocate($im,$color[1],$color[2],$color[3]);       $black = imagecolorallocate($im, 0x00, 0x00, 0x00);       imagecolortransparent($im,$white);       imagefilledrectangle($im, 0, 0, $size, 99, $white);       imagettftext($im,$size,90,$size,$h,$black,$font,$text);       @mkdir($dir);       imagepng($im,$filename);       imagedestroy($im);    }    $data = base64_encode(file_get_contents($filename));    return "<img src="cid:cfe6a2b5df9e43171622c6298178c6ae@phpmailer.0">";  

}


Solution:6

This thread suggests that you can write text to an image and then rotate the image.

It appears to be possible with IE but not with other browsers so it might be one of those little win for IE6 =)


Solution:7

imagettftext oughta do the trick.


Solution:8

As far as I know it's not possible to get vertical text with CSS, so that means that the rotated text has to be in an image. It's very straightforward to generate with PHP's' libgd interface to output an image file.

Note however that this means using one script to produce the image, and another to produce the surrounding web page. You can't generally (inline data: URI's notwithstanding) have one script produce more than one page component.


Solution:9

Use raphaeljs It works on IE 6 also

http://raphaeljs.com/text-rotation.html


Solution:10

   function verticletext($string)      {         $tlen = strlen($string);         for($i=0;$i<$tlen;$i++)         {              echo substr($string,$i,1)."<br />";            }      }  

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »