class Yzm{
protected $width;
protected $height;
protected $fangshi;
protected $size;
public function __construct($width,$height,$fangshi,$size)
{
$this->width=$width;
$this->height=$height;
$this->fangshi = $fangshi ;
$this->size = $size;
}
protected function a(){
return mt_rand(1000,9999);
}
protected function b(){
$s = “qwertyuioplkjhgfdsazxcvbnm”;
$a = str_shuffle($s);
return substr($a,2,4);
}
public function c(){
$s = “余幼时即嗜学家贫无从致书以观每假借于藏书之家手自笔录计日以还天大寒砚冰坚手指不可屈伸弗之怠录毕走送之不敢稍逾约以是人多以书假余余因得遍观群书既加冠益慕圣贤之道又患无硕师名人与游尝趋百里外从乡之先达执经叩问先达德隆望尊门人弟子填其室未尝稍降辞色余立侍左右援疑质理俯身倾耳以请或遇其叱咄色愈恭礼愈至不敢出一言以复俟其欣悦则又请焉故余虽愚卒获有所闻当余之从师也负箧曳屣行深山巨谷中穷冬烈风大雪深数尺足肤皲裂而不知至舍四支僵劲不能动媵人持汤沃灌以衾拥覆久而乃和寓逆旅主人日再食无鲜肥滋味之享同舍生皆被绮绣戴朱缨宝饰之帽腰白玉之环左佩刀右备容臭烨然若神余则缊袍敝衣处其间略无慕艳意以中有足乐者不知口体之奉不若人也盖余之勤且艰若此今虽耄老未有所成犹幸预君子之列而承天子之宠光缀公卿之后日侍坐备顾问四海亦谬称其氏名况才之过于余者乎”;
$a = substr($s,mt_rand(0,300)*3,3);
$a1 = substr($s,mt_rand(0,300)*3,3);
$a2 = substr($s,mt_rand(0,300)*3,3);
$a3 = substr($s,mt_rand(0,300)*3,3);
$stt= $a.$a1.$a2.$a3;
return $stt;
}
public function yzm(){
$im = imagecreatetruecolor($this->width,$this->height);
$color = imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
$color1 = imagecolorallocate($im,mt_rand(0,255),mt_rand(0,255),mt_rand(0,255));
imagefill($im,0,0,$color);
if($this->fangshi ==1){
$str = $this->a();
}elseif($this->fangshi==2){
$str = $this->b();
}else{
$str = $this->c();
}
imagettftext($im,$this->size,0,$this->width/5,$this->height/2.4,$color1,”simkai.ttf”,$str);
for ($z = 0; $z < 20; $z++) { $color4 = imagecolorallocate($im, mt_rand(1, 255), mt_rand(1, 255), mt_rand(1, 255)); imageline($im, mt_rand(1, 200), mt_rand(1, 200), mt_rand(1, 200), mt_rand(1, 200), $color4); } //画点 for ($i = 0; $i < 10000; $i++) { $a = mt_rand(0, 300); $b = mt_rand(0, 300); $color1 = imagecolorallocate($im, mt_rand(1, 255), mt_rand(1, 255), mt_rand(1, 255)); imagesetpixel($im, $a, $b, $color1); } header("content-type:image/jpeg");//设置图片的格式 imagejpeg($im);//设置图片的输出方式 默认是浏览器输出 设置第二个参数之后变成保存的路径 imagedestroy($im);//销毁变量 } }