帝国CMS任意字段转换为图片插件,支持中文英文数字生成,文章标题,电话号码、QQ号码均可,
<?php mb_internal_encoding("UTF-8");//设置编码 header ('Content-type:image/png'); require('../../class/connect.php');//引入数据库配置文件和公共函数文件 require('../../class/db_sql.php');//引入数据库操作文件 $link=db_connect();//连接MYSQL $empire=new mysqlquery();//声明数据库操作类 $editor=1;//声明目录层次 $classid=(int)$_GET['classid']; $id=(int)$_GET['id']; $area=addslashes($_GET['area']); $r1=$empire->fetch1("select tbname from {$dbtbpre}enewsclass where classid=$classid"); $tbname=$r1['tbname']; $r=$empire->fetch1("select $area from {$dbtbpre}ecms_$tbname where classid=$classid and id=$id"); /*16进制颜色转换为RGB色值*/ function hex2rgb($hexColor){ $color=str_replace('#','',$hexColor); if(strlen($color)>3){ $rgb = array('r'=>hexdec(substr($color,0,2)),'g'=>hexdec(substr($color,2,2)),'b'=>hexdec(substr($color,4,2))); }else{ $color=str_replace('#','',$hexColor); $r=substr($color,0,1).substr($color,0,1); $g=substr($color,1,1).substr($color,1,1); $b=substr($color,2,1).substr($color,2,1); $rgb=array('r'=>hexdec($r),'g'=>hexdec($g),'b'=>hexdec($b)); } return $rgb; } /*各种参数*/ $width=(int)$_GET['w']?(int)$_GET['w']:300; $hegih=(int)$_GET['h']?(int)$_GET['h']:50; $ff=$_GET['ff']?$_GET['ff']:'msyh'; $fontface='font/'.$ff.'.ttf'; $fontsize=$_GET['fz']?$_GET['fz']:12; $bcolor=$_GET['bc']?$_GET['bc']:'fff'; $tcolor=$_GET['tc']?$_GET['tc']:'000'; $b=hex2rgb($bcolor);//背景色 $t=hex2rgb($tcolor);//文字色 /*中英文换行等处理*/ function str_to_image($fontsize,$angle,$fontface,$string,$width){//这几个变量分别是 字体大小, 角度, 字体名称, 字符串, 预设宽度 $content="";//将字符串拆分成一个个单字 保存到数组 letter 中 for($i=0;$i<mb_strlen($string);$i++){ $letter[]=mb_substr($string,$i,1); } foreach($letter as $l){ $teststr=$content." ".$l; $testbox=imagettfbbox($fontsize,$angle,$fontface,$teststr); //判断拼接后的字符串是否超过预设的宽度 if (($testbox[2]>$width)&&($content!=="")){ $content.="\n"; } $content.=$l; } return $content; } $bg=imagecreate($width,$hegih);//创建白色画布 $background_color=imagecolorallocate($bg,$b['r'],$b['g'],$b['b']);//画布背景颜色 $text_color=imagecolorallocate($bg,$t['r'],$t['g'],$t['b']);//内容文字颜色 /**/ if($r[area]=''){ $text='No Data'; }else{ $text=stripslashes($r[$area]); } $text=str_to_image($fontsize,0,$fontface,$text,$width-10);//自动换行处理 //若文件编码为 GB2312 请将下行的注释去掉 //$text = iconv("GB2312", "UTF-8", $text); imagettftext($bg,$fontsize,0,10,20,$text_color,$fontface,$text);//输出图像 imagepng($bg); imagedestroy($bg); db_close();//关闭MYSQL链接 $empire=null;//注消操作类变量 ?>
<img src="[!--news.url--]e/extend/topic/index.php?classid=[!--classid--]&id=[!--id--]&w=500&h=100&area=title&ff=msyh&fz=12&bc=fff&tc=000" />
参数说明:
classid=信息所属栏目ID
id=信息ID
w=宽
h=高
area=显示变量的字段(如:qq)例如:[!--字段名--]:数据表字段内容调用,[!--newstime--]中的只要填入newstime即可
fz=字号大小
bc=图片背景颜色 (颜色为16进制代码)
tc=显示文字颜色 (颜色为16进制代码)
ff=字体名称,ttf格式的,放在 /e/extend/topic/font/ 下。
font目录下为你使用的字体存放,这个要必须放的,只要写入对应名字即可,例如 msyh.ttf 写入 msyh 即可。
在需要显示帝国cms站内搜索地方添加如下代码 formname=search_js1method=postaction=/e/search/index.phponsubmit=returnsearch_check(docume
?=esub(ReturnClassAddField(2,eclasspagetext),900,...,1)?答案就不说了吧,栏目2,esub截取xx字。
有两个字段值:“新家教、紧急”。通常我们用帝国CMS 标签调用 出是直接显示“新家教、紧急”文字的。如果想用上
帝国cms根据Tags 调用推荐相关文章,绝对好用! 以下是具体实现过程: 以下代码放到 /e/class/userfun.php 里! ?phpfunction