1、先创建公共方法,生成海报图的根方法,直接复制就可以用
提示:这里有一个问题,就是 getimagesize() 用来读取图片信息,但是只能读取http的,https的读取不到,会报错提示,这里要提前做下处理。
public function createPoster($config=[],$filename="")
{
if(empty($filename)) header("content-type: image/png");
$imageDefault = array(
'left'=>0,
'top'=>0,
'right'=>0,
'bottom'=>0,
'width'=>100,
'height'=>100,
'opacity'=>100
);
$textDefault = array(
'text'=>'',
'left'=>0,
'top'=>0,
'fontSize'=>32,
'fontColor'=>'255,255,255',
'angle'=>0,
);
$background = $config['background'];
$backgroundInfo = getimagesize($background);
$backgroundFun = 'imagecreatefrom'.image_type_to_extension($backgroundInfo[2], false);
$background = $backgroundFun($background);
$backgroundWidth = imagesx($background);
$backgroundHeight = imagesy($background);
$imageRes = imageCreatetruecolor($backgroundWidth,$backgroundHeight);
$color = imagecolorallocate($imageRes, 0, 0, 0);
imagefill($imageRes, 0, 0, $color);
imagecopyresampled($imageRes,$background,0,0,0,0,imagesx($background),imagesy($background),imagesx($background),imagesy($background));
if(!empty($config['image'])){
foreach ($config['image'] as $key => $val) {
$val