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.
#######################################################
# 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='data:image/png;base64,$data'>";
}
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='data:image/png;base64,$data'>";
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.
发布评论
评论(9)
该问题与服务器端语言无关。 如果垂直呈现的文本不再是文本而是图像时没有问题,请选择 tharkun提供的解决方案。 否则,在表示层有办法做到这一点。
首先,(目前)有一个仅限 IE 的解决方案,它是 CSS3 标准的一部分。 您可以实时查看。
CSS3 文本模块还指定了一些文本方向属性。
其他人使用 SVG 来 。
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.
The CSS3 text module also specify some properties for text orientation.
Other guys do it with SVG.
我不认为你可以用 PHP/HTML/CSS 旋转文本。 但是您可以使用包含垂直文本的 GD 创建图像。
例子:
I don't think you can rotate text with PHP/HTML/CSS. But you can create an image with GD containing vertical text.
Example:
你去那里没有回声
there you go no echo
其他浏览器也可以进行文本旋转。
CSS:
Text rotation is also possible with other browsers.
CSS:
如果表标题行太长,我使用下面的函数。 它非常有用,因为它易于使用、速度快,而且您无需计算文本高度和文本高度。 宽度。 那些 css 花招根本不起作用。
}
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.
}
此帖子建议您可以将文本写入图像,然后旋转图像。
IE 似乎可以,但其他浏览器不行,所以这可能是 IE6 的小胜利之一 =)
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 =)
据我所知,不可能使用 CSS 获得垂直文本,因此这意味着旋转的文本必须位于图像中。 使用 PHP 的
libgd
接口生成输出图像文件非常简单。但请注意,这意味着使用一个脚本来生成图像,并使用另一个脚本来生成周围的网页。 通常(内联数据:尽管有 URI)您不能让一个脚本生成多个页面组件。
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.
使用拉斐尔js
它也适用于 IE 6
http://raphaeljs.com/text-rotation.html
Use raphaeljs
It works on IE 6 also
http://raphaeljs.com/text-rotation.html