读取文件部分就不详细说了,用÷file_get_contents读取文件内的文字。然后用我写的这个简单的类,写入到图片,在另一个页面,<img src="" />src后面写上你这个x.php文件。关于几秒更新的问题,用<meta>标记设置一下几秒刷新下页面吧。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 );
}
} /* sample */
$image = new drawImg();
$image->setImage( 'mypic.gif' );
$image->setFont( 'simhei.ttf' );
$image->setContext( '我顶你个肺!' );
$image->setCharset('gb2312','UTF-8');
@$image->setColor('255,255,255','0,0,0,');
$image->draw( 20,0,0,20,'black' );//var_dump( $image->getImageInfo() );
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 );
}
} /* sample */
$image = new drawImg();
$image->setImage( 'mypic.gif' );
$image->setFont( 'simhei.ttf' );
$image->setContext( '我顶你个肺!' );
$image->setCharset('gb2312','UTF-8');
@$image->setColor('255,255,255','0,0,0,');
$image->draw( 20,0,0,20,'black' );//var_dump( $image->getImageInfo() );
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货