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