|
本帖最后由 winicfg 于 2011-4-18 18:01 编辑
求一个源码。就是回复姓名,显示该明星的源码。
比如这个帖子http://tieba.baidu.com/f?kz=985918335
补充,终于找到源码了,但是看不懂啊,哪位大神能指导一下怎么修改么?谢谢了!- <?php
- /**
- * @author shadowsniper(injection.mail@gmail.com)
- * @package ImageContext.class.php
- * @var object mImages 图片相关的数据
- * @descript 支持中文文字,但必须保证你的php环境支持iconv函数
- */
- class drawImg{
- var $mImages;
- /**
- * 设定本页面类型为图片类型
- */
- function __construct(){
- header("content-type:image/gif");
- }
-
- /**
- * 设置图片源
- *
- * @param string $filename
- * @example 'c://mypic/mypic.gif' or 'mypic.gif'
- */
- function setImage( $filename ){
- $this->mImages->filename = imagecreatefromgif( $filename );
- }
- /**
- * 设置写入文字的字体
- *
- * @param string $font
- * @example simhei.ttf
- */
- function setFont( $font ){
- $this->mImages->font = $font;
- }
-
- /**
- * 设置写入的文字
- *
- * @param string $context
- * @example test
- */
- function setContext( $context ){
- $this->mImages->context = $context;
- }
-
- /**
- * 设置文字编码
- *
- * @param string $from_charset
- * @param string $to_charset
- */
- function setCharset( $from_charset,$to_charset ){
- $this->mImages->context = iconv( $from_charset, $to_charset , $this->mImages->context );
- }
- /**
- * 设置写入黑白的具体数值
- *
- * @param string $white
- * @example 255,255,255
- * @param string $black
- * @example 0,0,0
- */
- function setColor( $white,$black ){
- $this->mImages->white = imagecolorallocate( $this->mImages->filename,$white );
- $this->mImages->black = imagecolorallocate( $this->mImages->filename,$black );
- }
-
- /**
- * 根据参数类型获取mImages对象属性或对象的信息
- *
- * @param enum 参数列表:filename,font,context,all
- * @return 一个mImages的一个属性或mImages这个对象
- */
- function getImageInfo( $type="all" ){
- if( $type != "all")
- return $this->mImages->$type;
- else
- return $this->mImages;
- }
-
- /**
- * 将文字写入图片
- *
- * @param int $size 字体大小
- * @param int $angle 起始角度
- * @param int $x 第一个字符的基本点(大概是字符的左下角)
- * @param int $y Y坐标。它设定了字体基线的位置,不是字符的最底端
- * @param enum $ 值为white或black
- */
- function draw( $size,$angle,$x,$y,$color ){
- imagettftext( $this->mImages->filename,$size,$angle,$x,$y,$this->mImages->$color,$this->mImages->font,$this->mImages->context );
- imagegif( $this->mImages->filename );
- }
- /**
- * 释放图片源
- */
- function unsetImage(){
- imagedestroy( $this->mImages->filename );
- }
- /**
- * 释放本对象
- */
- function __destruct(){
- unset( $this );
- }
- }
- //获取用户referer
- $referer = $_SERVER['HTTP_REFERER'];
- //获取相关帖子源代码
- $codes = file_get_contents($referer);
- //获取帖子最页最大值
- $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);
- //如果只有第一页
- if(!$result){
- //获取最后一个页面的源代码
- $codes = file_get_contents($referer);
- }
- //否则获取最大页
- else{
- $z=$matchs[1][0];
- $ct=$matchs[2][0];
- $lm=$matchs[3][0];
- $sc=$matchs[4][0];
- //获取一页显示多少帖子数
- $rn = $matchs[5][0];
- $tn='baiduPostBrowser';
- $word=urlencode($matchs[6][0]);
- //获取最大页数组key
- $num = count($matchs[7])/2-1;
- $maxThreadsPages = $matchs[7][$num]*$rn-$rn;
- unset($codes,$matchs);
- //组合最大页url
- $url = 'http://tieba.baidu.com/f?z='.$z.'&ct='.$ct.'&lm='.$lm.'&sc='.$sc.'&rn='.$rn.'&tn='.$tn.'&word='.$word.'&pn='.$maxThreadsPages;
- //获取最后一个页面的源代码
- $codes = file_get_contents($url);
- }
- //获取最后一个回帖的内容
- preg_match_all('/<cc>([^<]+)/is',$codes,$matchs);
- $maxkey = count($matchs[1])-1;
- $str = $matchs[1][$maxkey];
- /* 将最后一楼的内容画到图片上 */
- $image = new drawImg();
- $image->setImage( './Bluehills.gif' );
- $image->setFont( 'simhei.ttf' );
- $image->setContext( $str );
- $image->setCharset('gb2312','UTF-8');
- @$image->setColor('255,255,255','0,0,0,');
- $image->draw( 20,0,0,20,'black' );
- ?>
复制代码 再次补充:
我按照2楼的方法,结果打开***.php显示- 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
- 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
- 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
- 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
- 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
- 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
复制代码 |
|