$image='xiaofl.jpg';
$img=getimagesize($image);
switch ($img[2])
{
case 1:
$im =imagecreatefromgif($image);
break;
case 2:
$im =imagecreatefromjpeg($image);
break;
case 3:
$im =imagecreatefrompng($image);
break;
}
$word=imagecolorallocate($im,212,0,0);
$str=iconv("gbk","utf-8","新年快乐php100.com");
imagettftext($im,12,0,20,20,$word,'simkai.ttf',$str);
header("content-type: image/jpeg");
Imagejpeg($im);
我想将这个封装成一个类,请问我该怎么写我自己写了一个但是错误之多自己都不好意思了,所以请教高手,我也吧我写的贴出来希望那高手帮帮忙,帮我写一个
class image{
private $image;
function __construct($image){
$this->image=$image;
}
function img(){
$img=getimagesize($this->image);
switch ($img[2]){
case 1:
$im =imagecreatefromgif($this->image);
break;
case 2:
$im =imagecreatefromjpeg($this->image);
break;
case 3:
$im =imagecreatefrompng($this->image);
break;
}
return $im;
}
function imgcreat($w,$h){
imagecreatetruecolor($w,$h);
}
function imagelocte($c,$c1,$c2){
ImageColorAllocate($this->img(),$c,$c1,$c2);
}
function iconv($str){
iconv("gbk","utf-8","'$str'");
}
function text($t1,$t2,$t3,$t4,$word){
imagettftext($this->img(), $t1,$t2,$t3,$t4,$this->imagelocte(),'$word',$this->iconv);
}
function head($type){
header("content-type: image/$type");
Imagejpeg($this->img);
}
}
$image=new image("0001.php");
$image->img();
$image->head('jpeg');
