$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);
$image=’xiaofl.jpg’; $img=getimagesize($image); switch ($img[2]) { case 1: $im =imagecreatefromgif($image); break; case 2: $im =imagecreatefromjpeg($image);
Share
There are a lot of ways to do this. You’ll generally want to decide on a single responsibility for each of your classes. Then you will code the class to meet that responsibility in as general a way as possible. In this case, the responsibility might be to display an image with some text added(?).
Here’s one way to do it: