我想在PHP中用垂直文本放一张图片:
function scrivi($scrivi, $p) {
$imgResource = imagecreatefromjpeg($p);
$textcolor = imagecolorallocate($imgResource, 255, 255, 255);
$fontPath = "st.ttf";
$fontSize = "18";
$rotation = "270"; // counter-clockwise rotation
$text = "this is a text";
$textCoords = imagettfbbox($fontSize, $rotation, $fontPath, $text);
$x = 36;
$y = 36;
imagettftext($imgResource, $fontSize, $rotation, $x, $y, $textcolor, $fontPath, $text);
unlink($p);
imagejpeg($imgResource, $p, 100);
imagedestroy($imgResource);
}
它的效果很好我只希望字母被转动这是一个使用函数
的例子
相反,我想
一个想法可能是包装每个字母
答案 0 :(得分:0)
您真正需要做的就是将文本拆分为数组,循环播放,然后将y
偏移高度+字体字符的前导:
function scrivi($p,$text)
{
$imgResource = imagecreatefromjpeg($p);
$textcolor = imagecolorallocate($imgResource, 255,255, 255);
$fontPath = __DIR__."/st.ttf";
$fontSize = "18";
$x = 36 ;
$y = 36;
foreach(str_split($text) as $char) {
$textCoords = imagettfbbox($fontSize, 0, $fontPath, $char);
imagettftext($imgResource, $fontSize, 0, $x, $y, $textcolor,$fontPath,$char);
$y += 24;
}
unlink($p);
imagejpeg($imgResource,$p,100);
imagedestroy($imgResource);
}
scrivi('http://imgtops.sourceforge.net/bakeoff/bw.jpg',"Cats are great");
给你: