我需要水印带有弯曲文字的图像。我已经浏览了一些互联网网站,但我找不到我需要的代码。有人请告诉我如何在php中生成弯曲文本
感谢和问候
tismon
答案 0 :(得分: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;
}
}
?>
答案 1 :(得分:0)
请查看以下链接。
http://www.phpjabbers.com/phpexample.php?eid=20
http://articles.sitepoint.com/article/watermark-images-php
http://coding.derkeiler.com/Archive/PHP/alt.php/2004-12/0061.html
答案 2 :(得分:0)
您可以使用Gimp或Photoshop之类的图形设计软件,但是您需要学习创建弯曲文本的所有步骤。
您还可以使用MockoFun之类的简单在线工具来创建curved or circle text。
以下是如何执行此操作的视频:https://www.youtube.com/watch?v=-rapX6WRL-U
想法是在软件中上传图像,创建弯曲的文本,降低不透明度,使文本变为透明,然后保存图像。
或者,您可以创建弯曲的文本,降低其不透明度,然后将其另存为PNG(具有透明度)。这样,您将拥有一个PNG水印图像,可以重复使用以添加到多个图像上。