[英]Php Colored Words, Centered and Multiline Text
Multiline text, centered, each word must be of different color.多行文本,居中,每个单词必须是不同的颜色。 I've tried too many methods.
我试过太多方法了。 But none of them could do what I wanted.
但他们都不能做我想做的事。 How can this be an easy and trouble-free way?
这怎么可能是一种简单而无故障的方法?
How can the text be divided into words of 3-4, with the same color background, each with a different color?如何将文字分成3-4个字,背景颜色相同,每个字颜色不同?
$metin="Music Industry Sharks How to Uncover the Unscrupulous Many in the Music Business"; $metin="Music Industry Sharks 如何揭开音乐行业不法分子的面纱";
Example with still gd library:带有静止 gd 库的示例:
use GDText\Box;
use GDText\Color;
$files = glob('./fontlar/*.ttf');
$fontik = implode("||", $files);
$fontik2=$fontik;
$metin="Music Industry Sharks How to Uncover the Unscrupulous Many in the Music Business";
$metin=preg_replace("/[^A-Za-z0-9öÖüÜéèêôÄäçÇŞşĞğİı ]/", '', $metin);
$yenimetin=str_replace('-','',$metin);
$yenimetin=str_replace("\n",'',$yenimetin);
$yenimetinp = wordwrap($yenimetin, 1, "<br>", false);
echo $yenimetinp;
$prc=explode('<br>',$yenimetinp);
$i=0;
while ($i<=substr_count($yenimetinp,'<br>')) {
if (substr_count($fontik2,'||')<=0); $fontik2=$fontik;
$nafont=explode('||',$fontik2);
$nafont=$nafont[rand(0,substr_count($fontik2,'||'))];
$fontik2=str_replace($nafont.'||','',$fontik2);
$fontik2=str_replace('||'.$nafont,'',$fontik2);
$im = imagecreatetruecolor(2000, 1000);
$backgroundColor = imagecolorallocate($im, 0, 18, 64);
imagefill($im, 0, 0, $backgroundColor);
$renkler=array("#FFFFFF","#99FF00","#FFCC00","#ACF17E","#92E4E4","#FFFF33","#00FF66");
$rgb = hex2rgb($renkler[array_rand($renkler)]);
$r=$rgb[0];
$g=$rgb[1];
$b=$rgb[2];
$box = new Box($im);
$box->setFontFace(__DIR__.$nafont);
$box->setFontColor(new Color($r, $g, $b));
$box->setTextShadow(new Color(0, 0, 0, 50), 2, 2);
$box->setFontSize(150);
$box->setBox(strlen($prc[$i]), 20, 1800, 1000);
$box->setTextAlign('left', 'center');
$box->draw($prc[$i]);
$renkler=array("#FFFFFF","#99FF00","#FFCC00","#ACF17E","#92E4E4","#FFFF33","#00FF66");
$rgb = hex2rgb($renkler[array_rand($renkler)]);
$r=$rgb[0];
$g=$rgb[1];
$b=$rgb[2];
$box->setFontFace(__DIR__.$nafont);
$box->setFontColor(new Color($r, $g, $b));
$box->setTextShadow(new Color(0, 0, 0, 50), 2, 2);
$box->setFontSize(150);
$box->setBox(strlen($prc[$i])*100, 20, 1800, 1000);
$box->setTextAlign('left', 'center');
$box->draw($prc[$i+1]);
$renkler=array("#FFFFFF","#99FF00","#FFCC00","#ACF17E","#92E4E4","#FFFF33","#00FF66");
$rgb = hex2rgb($renkler[array_rand($renkler)]);
$r=$rgb[0];
$g=$rgb[1];
$b=$rgb[2];
$box->setFontFace(__DIR__.$nafont);
$box->setFontColor(new Color($r, $g, $b));
$box->setTextShadow(new Color(0, 0, 0, 50), 2, 2);
$box->setFontSize(150);
$box->setBox(strlen($prc[$i+1])*150, 20, 1800, 1000);
$box->setTextAlign('left', 'center');
$box->draw($prc[$i+2]);
imagepng($im,'./tmp/test'.$i.'.png');
/*
$cropped = imagecropauto($im, IMG_CROP_SIDES);
imagepng($cropped,'./tmp/test'.$i.'.png');
imagedestroy( $cropped );
*/
$i++;
}
Failed .失败。
sign valid css colours in var colors bellow在下面的 var 颜色中签署有效的 css 颜色
var colors = ["#ED401B", "blue", "red", "green", "yellow"];
$('#your-text').html(function (i, text) {
return $.map(text.split(' '), function (word) {
return '<div style="color:'
+ colors[Math.floor(Math.random() * colors.length)]
+ '">' + word + '</div>';
}).join(' ');
});
Here is jsfiddle: https://jsfiddle.net/4fhvsw1j/1/这是 jsfiddle: https ://jsfiddle.net/4fhvsw1j/1/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.