加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

生成新闻页头部和flash图片

发布时间:2020-12-15 06:31:06 所属栏目:百科 来源:网络整理
导读:一、实现方法1)标题图片字体定义 首先上传字体文件上传到include/data/fonts/下,并命名为 STXINGKA.TTF (字体下载),这个是用于生成标题图片的字体的。当然,你也可以自己定义更漂亮的字体,但字体必须命名为STXINGKA.TTF。 2)标题图片函数文件 打开inc

一、实现方法1)标题图片字体定义

首先上传字体文件上传到include/data/fonts/下,并命名为 STXINGKA.TTF (字体下载),这个是用于生成标题图片的字体的。当然,你也可以自己定义更漂亮的字体,但字体必须命名为STXINGKA.TTF。

2)标题图片函数文件

打开include/extend.func.php (注意:本文件为自定义函数接口,如果你没有这个文件,请自己创建一个),在最后面的?>的前面以上开始插入以下代码:

折叠展开PHP 代码复制内容到剪贴板
  1. class?DeDeTitle ??
  2. { ??
  3. ????var?$text?=?'暂无标题'; ??
  4. ????var?$bg?=?'#F0F0F0'; ??
  5. ????var?$color?=?'#30F'; ??
  6. ????var?$width?=?500; ??
  7. ????var?$height?=?50; ??
  8. ????var?$size?=?30; ??
  9. ????var?$font; ??
  10. ????var?$path; ??
  11. ????function?__construct($t) ??
  12. ????{ ??
  13. ????????if($t) ??
  14. ????????{ ??
  15. ????????????$this->text?=?$t; ??
  16. ????????} ??
  17. ????????$this->font?=?DEDEINC.'/data/fonts/STXINGKA.TTF'; ??
  18. ????} ??
  19. ????function?DeDeTitle($t) ??
  20. ????{ ??
  21. ????????$this->__construct($t); ??
  22. ????} ??
  23. ????function?TextConv() ??
  24. ????{ ??
  25. ????????global?$cfg_soft_lang; ??
  26. ????????if($cfg_soft_lang!='utf-8') ??
  27. ????????{ ??
  28. ????????????return?gb2utf8($this->text); ??
  29. ????????} ??
  30. ????????return?$this->text; ??
  31. ????} ??
  32. ????function?C($color,$rgb) ??
  33. ????{??? ??
  34. ????????if(strlen($color)==4) ??
  35. ????????{ ??
  36. ????????????for($i=1;$i<4;$i++) ??
  37. ????????????{ ??
  38. ????????????????$str?.=?str_repeat($color[$i],2); ??
  39. ????????????} ??
  40. ????????????$color?=?'#'.$str; ??
  41. ????????} ??
  42. ????????switch($rgb) ??
  43. ????????{ ??
  44. ????????????case?'R':????return?hexdec(substr($color,?1,?2)); ??
  45. ????????????case?'B':????return?hexdec(substr($color,?3,?2)); ??
  46. ????????????case?'G':????return?hexdec(substr($color,?5,?2)); ??
  47. ????????} ??
  48. ????} ??
  49. ????function?Titlepath() ??
  50. ????{ ??
  51. ????????global?$cfg_medias_dir; ??
  52. ????????$name?=?GetPinyin($this->text).'.gif'; ??
  53. ????????$path?=?$cfg_medias_dir.'/title/'; ??
  54. ????????if(!is_dir($path)) ??
  55. ????????{ ??
  56. ????????????CreateDir($path); ??
  57. ????????} ??
  58. ????????return?$path.$name; ??
  59. ????} ??
  60. ????function?Show() ??
  61. ????{ ??
  62. ????????if(!file_exists(DEDEROOT.$this->Titlepath())) ??
  63. ????????{ ??
  64. ????????????$this->Make(); ??
  65. ????????} ??
  66. ????????global?$cfg_cmsurl; ??
  67. ????????return??'<img?src="'.$cfg_cmsurl.$this->Titlepath().'"/>'; ??
  68. ????} ??
  69. ????function?Make() ??
  70. ????{ ??
  71. ????????$image?=?imagecreatetruecolor($this->width,$this->height); ??
  72. ????????$bg?=?ImageColorAllocate($image,$this->C($this->bg,'R'),'B'),'G')); ??
  73. ????????$color?=?ImageColorAllocate($image,$this->C($this->color,'G')); ??
  74. ????????ImageFilledRectangle($image,$this->width,$this->height,$bg); ??
  75. ????????imagettftext($image,$this->size,?0,?$this->size/2,?($this->height+$this->size)/2,?$color,?$this->font,$this->TextConv()); ??
  76. ????????imagegif($image,DEDEROOT.$this->Titlepath()); ??
  77. ????????imagedestroy($image); ??
  78. ????} ??
  79. }??
3)调用方法简单说明

实际上我们知道,在织梦(DedeCMS)系统中,处理底层字段,一般来说有两种方法:

  1. function
  2. runphp

这两种方法的知识不在本教程讲解的重点,大家可查阅相关资料了解!

我们这里的标题图片,运用的就是第二种runphp来处理的,调用方法为:

在arclist标签中:

[field:title runphp='yes']
$title = new DeDeTitle(@me);//使用DedeTile类
$title->bg = '#F0F0F0';//标题图片背静颜色
$title->color = '#30F';//标题图片字体颜色
$title->width = 350;//标题图片的宽度
$title->height = 50;//标题图片的高度
$title->size = 25;//标题图片的字体大小
@me=$title->Show();//显示图片
[/field:title]

如果在是内容页运用,只需要将[field:title/]换成 {dede:field.title/}即可,例如:

{dede:field.title runphp='yes'}
$title = new DeDeTitle(@me);//使用DedeTile类
$title->bg = '#F0F0F0';//标题图片背静颜色
$title->color = '#30F';//标题图片字体颜色
$title->width = 350;//标题图片的宽度
$title->height = 50;//标题图片的高度
$title->size = 25;//标题图片的字体大小
@me=$title->Show();//显示图片
{/dede:field.title/}

二、效果预览

我们在后台的【模板】——[全局标记测试]中输入以下代码:

{dede:arclist row='1' typeid=''}
<a href="[field:arcurl/]">[field:title runphp='yes']
$title = new DeDeTitle(@me);
$title->bg = '#F0F0F0';
$title->color = '#30F';
$title->width = 350;
$title->height = 50;
$title->size = 25;
@me=$title->Show();
[/field:title]</a>
{/dede:arclist}
?

后,看到了如下的效果:

?

怎么样?是不是很酷?赶快尝试吧。

三、其它说明

这里的这个是一个现成的库,他不仅仅可以生成标题图片,也可以生成一些其它的内容。只要你会使用本函数中所介绍的几个参数即可。


dede生成新闻页头部

{dede:arclist row='1' flag='h' titlelen=42}

<a href="[field:arcurl/]">[field:title runphp='yes']
$title = new DeDeTitle(@me);
$title->bg = '#FFFFFF';
$title->color = '#000';
$title->width = 710;
$title->height = 50;
$title->size = 25;
@me=$title->Show();
[/field:title]</a>

{/dede:arclist}

<!--生成flash-->

<script language='javascript'> linkarr = new Array(); picarr = new Array(); textarr = new Array(); var swf_width=400; var swf_height=245; //文字颜色|文字位置|文字背景颜色|文字背景透明度|按键文字颜色|按键默认颜色|按键当前颜色|自动播放时间|图片过渡效果|是否显示按钮|打开方式 var configtg='0xffffff|1|#0A0262|5|0xffffff|0xC5DDBC|0x000033|5|3|1|_blank'; var files = ""; var links = ""; var texts = ""; //这里设置调用标记 {dede:arclist flag='f' row='5'titlelen=50} linkarr[[field:global.autoindex/]] = "[field:arcurl/]"; picarr[[field:global.autoindex/]]? = "[field:litpic/]"; textarr[[field:global.autoindex/]] = "[field:title function='html2text(@me)'/]"; {/dede:arclist} for(i=1;i<picarr.length;i++){ if(files=="") files = picarr[i]; else files += "|"+picarr[i]; } for(i=1;i<linkarr.length;i++){ if(links=="") links = linkarr[i]; else links += "|"+linkarr[i]; } for(i=1;i<textarr.length;i++){ if(texts=="") texts = textarr[i]; else texts += "|"+textarr[i]; } document.write('<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0" width="'+ swf_width +'" height="'+ swf_height +'">'); document.write('<param name="movie" value="{dede:global.cfg_templeturl /}/default/images/bcastr3.swf"><param name="quality" value="high">'); document.write('<param name="menu" value="false"><param name=wmode value="opaque">'); document.write('<param name="FlashVars" value="bcastr_file='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'&bcastr_config='+configtg+'">'); document.write('<embed src="{dede:global.cfg_templeturl /}/default/images/bcastr3.swf" wmode="opaque" FlashVars="bcastr_file='+files+'&bcastr_link='+links+'&bcastr_title='+texts+'&bcastr_config='+configtg+'&menu="false" quality="high" width="'+ swf_width +'" height="'+ swf_height +'" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />'); document.write('</object>'); </script>

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读