|
|
class generaterandomimage
{
public $imgwidth = 272;
public $imgheight = 162;
public $type = '';
public $text = '';
public $fontsize = 16;
public function __construct($type, $text)
{
$this->type = $type;
$this->text = $text;
}
public function createimg()
{
$backgroundcolor = imagecolorallocate($image, $rgb['r'], $rgb['g'], $rgb['b']);
$textcolor = imagecolorallocate($image, 255, 255, 255);
$font = $_server['document_root'].'/public/font/simhei.ttf';
$x = 18;
$y = 50;
$angle = 0;
imagettftext($image, $this->fontsize, $angle, $x, $y, $textcolor, $font, $this->text);
$waterimgpath = $this->randwaterimage();
$waterinfo = getimagesize($waterimgpath);
$watertype = image_type_to_extension($waterinfo[2], false);
$createimagefunc = 'imagecreatefrom'.$watertype;
$mask = $createimagefunc($waterimgpath);
$posx = $this->imgwidth - $waterinfo[0];
$posy = $this->imgheight - $waterinfo[1];
header("content-type:image/png");
imagecopy($image, $mask, $posx, $posy, 0, 0, $waterinfo[0], $waterinfo[1]);
imagepng($image);
imagedestroy($image);
}
public function getbackground()
{
$background = [
'1'=>['r'=>0, 'g'=>160,'b'=>233],
'2'=>['r'=>198,'g'=>0, 'b'=>110],
'3'=>['r'=>237,'g'=>109,'b'=>0],
'4'=>['r'=>33, 'g'=>148,'b'=>75],
'5'=>['r'=>63, 'g'=>58, 'b'=>57],
'6'=>['r'=>202,'g'=>162,'b'=>101],
];
return $background[$this->type];
}
public function randwaterimage()
{
$folder = [
'1'=>'product','2'=>'team','3'=>'architecture','4'=>'developer','5'=>'test','6'=>'engineer'
];
$targetfolder = $_server['document_root'].'/public/images/role/'.$folder[$this->type].'/'.rand(1,38).'.png';
return $targetfolder;
}
}
$image = new generaterandomimage(1,"扛得住的mysql数据架构");
$image->createimg();
|