1
A
回答
1
这可能帮助:
https://forums.phpfreaks.com/topic/57542-image-manipulation-skewing-text-text-on-a-curve/
<?php
/*********************************************
* Fitting text to arc
*
* TextOnArc
* Author : Barand August2007
**********************************************/
$im = imagecreate(400,400);
$white = imagecolorallocate($im, 0xFF, 0xFF, 0xFF);
$grey = imagecolorallocate($im, 0xCC, 0xCC, 0xCC);
$txtcol = imagecolorallocate($im, 0xFF, 0x00, 0x00);
$r = 150;
$cx = 200;
$cy = 200;
$txt1 = 'Text on an Arc';
$txt2 = 'by Barand';
$font = 'arial.ttf';
#$font = 'bauhausm.ttf';
$size = 48;
imagearc($im,$cx,$cy,$r*2,$r*2,$s,$e,$grey);
$pad = 2; // extra char spacing for text
$s = 180;
$e = 360;
textOnArc($im,$cx,$cy,$r,$s,$e,$txtcol,$txt1,$font,$size,$pad);
$pad = 6; // extra char spacing for text
$s = 0;
$e = 180;
textInsideArc($im,$cx,$cy,$r,$s,$e,$txtcol,$txt2,$font,$size,$pad);
header("content-type: image/png");
imagepng($im);
imagedestroy($im);
function textWidth($txt, $font, $size)
{
$bbox = imagettfbbox($size,0,$font,$txt);
$w = abs($bbox[4]-$bbox[0]);
return $w;
}
function textOnArc($im,$cx,$cy,$r,$s,$e,$txtcol,$txt,$font,$size, $pad=0)
{
$tlen = strlen($txt);
$arccentre = ($e + $s)/2;
$total_width = textWidth($txt, $font, $size) - ($tlen-1)*$pad;
$textangle = rad2deg($total_width/$r);
$s = $arccentre - $textangle/2;
$e = $arccentre + $textangle/2;
for ($i=0, $theta = deg2rad($s); $i < $tlen; $i++)
{
$ch = $txt{$i};
$tx = $cx + $r*cos($theta);
$ty = $cy + $r*sin($theta);
$dtheta = (textWidth($ch,$font,$size))/$r;
$angle = rad2deg(M_PI*3/2 - ($dtheta/2 + $theta));
imagettftext($im, $size, $angle, $tx, $ty, $txtcol, $font, $ch);
$theta += $dtheta;
}
}
function textInsideArc($im,$cx,$cy,$r,$s,$e,$txtcol,$txt,$font,$size, $pad=0)
{
$tlen = strlen($txt);
$arccentre = ($e + $s)/2;
$total_width = textWidth($txt, $font, $size) + ($tlen-1)*$pad;
$textangle = rad2deg($total_width/$r);
$s = $arccentre - $textangle/2;
$e = $arccentre + $textangle/2;
for ($i=0, $theta = deg2rad($e); $i < $tlen; $i++)
{
$ch = $txt{$i};
$tx = $cx + $r*cos($theta);
$ty = $cy + $r*sin($theta);
$dtheta = (textWidth($ch,$font,$size)+$pad)/$r;
$angle = rad2deg(M_PI/2 - ($theta - $dtheta/2));
imagettftext($im, $size, $angle, $tx, $ty, $txtcol, $font, $ch);
$theta -= $dtheta;
}
}
?>
0
相关问题
- 1. 写上弧(PHP)弯曲文本
- 2. 如何在as3中弯曲文本?
- 3. 在弯曲项目中显示弯曲
- 4. 弯曲文本出发点
- 5. SVG崩溃中的弯曲文本Chrome
- 6. 沿着路径在PHP中弯曲文本?
- 7. 三JS弯曲(弯曲)CSS3DObject
- 8. 使用HTML&CSS的弯曲文本
- 9. PHP功能弯曲/扭曲图像
- 10. 在OpenLayers中创建弯曲的已知文本LineString
- 11. css中的弯曲边框
- 12. “弯曲”3D中的UIView
- 13. 在侧面弯曲的Div
- 14. 在IE8弯曲的角落?
- 15. 在flex中弯曲文本而不转换为栅格图形?
- 16. 龟弯曲线
- 17. 直线弯曲
- 18. 弯曲图像
- 19. 调用弯曲
- 20. 弯曲的UITableView/UIScrollView
- 21. Gef BendPoints弯曲的
- 22. 弯曲的Y轴
- 23. 转换卷曲弯曲
- 24. 如何弯曲android canvas中的文本区域?
- 25. 加入字体样式到弯曲文本中的jquery
- 26. 在Three.JS中构建弯曲的BoxGeometry .JS
- 27. 在CSS中稍微弯曲的边框
- 28. 在cocos2d弯曲标签
- 29. 在elasticsearch和弹性弯曲
- 30. CSS3弯曲效果
链接现在处于404状态 – gvgvgvijayan 2014-02-27 09:25:46
我已更新到工作链接 – Softnux 2018-01-03 13:42:11