找回密码
 注册
搜索
免费空间 免费域名 免费AI 老牌主机商首月仅1美分!27美元/年!Spaceship优惠码 Namecheap优惠码阿里云2核2G3M新老续费同享99元/年!
查看: 350|回复: 4

[程序代码] 一个源码。就是回复姓名,显示该明星的源码。

[复制链接]
发表于 2011-4-17 20:08:40 | 显示全部楼层 |阅读模式
本帖最后由 winicfg 于 2011-4-18 18:01 编辑

求一个源码。就是回复姓名,显示该明星的源码。
比如这个帖子http://tieba.baidu.com/f?kz=985918335

补充,终于找到源码了,但是看不懂啊,哪位大神能指导一下怎么修改么?谢谢了!
  1. <?php
  2. /**
  3. * @author shadowsniper(injection.mail@gmail.com)
  4. * @package ImageContext.class.php
  5. * @var object mImages 图片相关的数据
  6. * @descript 支持中文文字,但必须保证你的php环境支持iconv函数
  7. */
  8. class drawImg{
  9. var $mImages;

  10. /**
  11.   * 设定本页面类型为图片类型
  12.   */
  13. function __construct(){
  14.   header("content-type:image/gif");
  15. }

  16. /**
  17.   * 设置图片源
  18.   *
  19.   * @param string $filename
  20.   * @example 'c://mypic/mypic.gif' or 'mypic.gif'
  21.   */
  22. function setImage( $filename ){
  23.   $this->mImages->filename = imagecreatefromgif( $filename );
  24. }

  25. /**
  26.   * 设置写入文字的字体
  27.   *
  28.   * @param string $font
  29.   * @example simhei.ttf
  30.   */
  31. function setFont( $font ){
  32.   $this->mImages->font = $font;
  33. }


  34. /**
  35.   * 设置写入的文字
  36.   *
  37.   * @param string $context
  38.   * @example test
  39.   */
  40. function setContext( $context ){
  41.   $this->mImages->context = $context;
  42. }

  43. /**
  44.   * 设置文字编码
  45.   *
  46.   * @param string $from_charset
  47.   * @param string $to_charset
  48.   */
  49. function setCharset( $from_charset,$to_charset ){
  50.   $this->mImages->context = iconv( $from_charset, $to_charset , $this->mImages->context );
  51. }

  52. /**
  53.   * 设置写入黑白的具体数值
  54.   *
  55.   * @param string $white
  56.   * @example 255,255,255
  57.   * @param string $black
  58.   * @example 0,0,0
  59.   */
  60. function setColor( $white,$black ){
  61.   $this->mImages->white = imagecolorallocate( $this->mImages->filename,$white );
  62.   $this->mImages->black = imagecolorallocate( $this->mImages->filename,$black );
  63. }

  64. /**
  65.   * 根据参数类型获取mImages对象属性或对象的信息
  66.   *
  67.   * @param enum 参数列表:filename,font,context,all
  68.   * @return 一个mImages的一个属性或mImages这个对象
  69.   */
  70. function getImageInfo( $type="all" ){
  71.   if( $type != "all")
  72.    return $this->mImages->$type;
  73.   else
  74.    return $this->mImages;
  75. }


  76. /**
  77.   * 将文字写入图片
  78.   *
  79.   * @param int $size 字体大小
  80.   * @param int $angle 起始角度
  81.   * @param int $x 第一个字符的基本点(大概是字符的左下角)
  82.   * @param int $y Y坐标。它设定了字体基线的位置,不是字符的最底端
  83.   * @param enum $  值为white或black
  84.   */
  85. function draw( $size,$angle,$x,$y,$color ){
  86.   imagettftext( $this->mImages->filename,$size,$angle,$x,$y,$this->mImages->$color,$this->mImages->font,$this->mImages->context );
  87.   imagegif( $this->mImages->filename );
  88. }

  89. /**
  90.   * 释放图片源
  91.   */
  92. function unsetImage(){
  93.   imagedestroy( $this->mImages->filename );
  94. }

  95. /**
  96.   * 释放本对象
  97.   */
  98. function __destruct(){
  99.   unset( $this );
  100. }
  101. }

  102. //获取用户referer
  103. $referer = $_SERVER['HTTP_REFERER'];

  104. //获取相关帖子源代码
  105. $codes = file_get_contents($referer);

  106. //获取帖子最页最大值
  107. $result = preg_match_all('/<a href=\/f\?z=(\d+)&ct=(\d+)&lm=(\d)&sc=(\d)&rn=(\d+)&tn=baiduPostBrowser&word=(.+?)&pn=\d+>\[(\d+)\]/is',$codes,$matchs);

  108. //如果只有第一页
  109. if(!$result){
  110.     //获取最后一个页面的源代码
  111.     $codes = file_get_contents($referer);
  112. }
  113. //否则获取最大页
  114. else{
  115.     $z=$matchs[1][0];
  116.     $ct=$matchs[2][0];
  117.     $lm=$matchs[3][0];
  118.     $sc=$matchs[4][0];
  119.     //获取一页显示多少帖子数
  120.     $rn = $matchs[5][0];
  121.     $tn='baiduPostBrowser';
  122.     $word=urlencode($matchs[6][0]);

  123.     //获取最大页数组key
  124.     $num = count($matchs[7])/2-1;
  125.     $maxThreadsPages = $matchs[7][$num]*$rn-$rn;

  126.     unset($codes,$matchs);

  127.     //组合最大页url
  128.     $url = 'http://tieba.baidu.com/f?z='.$z.'&ct='.$ct.'&lm='.$lm.'&sc='.$sc.'&rn='.$rn.'&tn='.$tn.'&word='.$word.'&pn='.$maxThreadsPages;

  129.     //获取最后一个页面的源代码
  130.     $codes = file_get_contents($url);
  131. }

  132. //获取最后一个回帖的内容
  133. preg_match_all('/<cc>([^<]+)/is',$codes,$matchs);
  134. $maxkey = count($matchs[1])-1;
  135. $str = $matchs[1][$maxkey];

  136. /* 将最后一楼的内容画到图片上 */
  137. $image = new drawImg();
  138. $image->setImage( './Bluehills.gif' );
  139. $image->setFont( 'simhei.ttf' );
  140. $image->setContext( $str );
  141. $image->setCharset('gb2312','UTF-8');
  142. @$image->setColor('255,255,255','0,0,0,');
  143. $image->draw( 20,0,0,20,'black' );
  144. ?>
复制代码
再次补充:
我按照2楼的方法,结果打开***.php显示
  1. Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /data/multiserv/users/479404/projects/1367822/www/mypic.gif/index.php on line 119

  2. Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /data/multiserv/users/479404/projects/1367822/www/mypic.gif/index.php on line 127

  3. Warning: Cannot modify header information - headers already sent by (output started at /data/multiserv/users/479404/projects/1367822/www/mypic.gif/index.php:119) in /data/multiserv/users/479404/projects/1367822/www/mypic.gif/index.php on line 15

  4. Warning: imagecreatefromgif(./Bluehills.gif) [function.imagecreatefromgif]: failed to open stream: No such file or directory in /data/multiserv/users/479404/projects/1367822/www/mypic.gif/index.php on line 25

  5. Warning: imagettftext() expects parameter 1 to be resource, boolean given in /data/multiserv/users/479404/projects/1367822/www/mypic.gif/index.php on line 96

  6. Warning: imagegif() expects parameter 1 to be resource, boolean given in /data/multiserv/users/479404/projects/1367822/www/mypic.gif/index.php on line 97
复制代码
发表于 2011-4-17 20:32:52 | 显示全部楼层
不知道,绑定
发表于 2011-4-17 23:08:42 | 显示全部楼层
上传为xx.php
<img src="xx.php">放到你的贴吧中
发表于 2011-4-18 16:41:51 | 显示全部楼层
迷胡
发表于 2011-4-19 20:58:35 | 显示全部楼层
标记学习
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|小黑屋|免费吧论坛

GMT+8, 2024-5-5 04:30 , Processed in 0.021156 second(s), 5 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表