1、画布创建
$im = new \Imagick($bjimage); //从图片创建画布
$srcWH = $im->getImageGeometry(); //获取画布尺寸
$canvas = new \Imagick();
//画布空白画布
$canvas->newImage( $srcWH['width'], $srcWH['height'], 'white', 'png' );
2.图片缩放
$im->thumbnailImage($srcWH['width'],$srcWH['height'],false);
//指定图片类型格式化
$sharebg->setImageFormat( "jpg" );
3.把sharebg图片贴到im图片上
$im->compositeImage($sharebg,\Imagick::COMPOSITE_OVER,0,0);
4. 头像avatar切成圆形
$avatar=new\Imagick($info['avatar']);
// example values
$width = 87;
$height = 87;
// create mask image
$mask = new Imagick();
$mask->newImage($width, $height, new ImagickPixel('transparent'), 'png');
// create the rounded rectangle
$shape = new ImagickDraw();
$shape->setFillColor(new ImagickPixel('white'));
$shape->roundRectangle(0, 0, $width, $height, ($width/2)+1, ($height/2)+1);
// draw the rectangle
$mask->drawImage($shape);
// apply mask
$avatar->compositeImage($mask, Imagick::COMPOSITE_DSTIN, 0, 0);
5.加文字
$draw = new \ImagickDraw();
$draw->setFontSize(27);//设置字体大小
$draw->setFillColor('#F6970B');//设置字体颜色
$draw->setFontWeight ( 800 );
$draw->setFont('assets/fonts/msyh.ttf');
$draw->setTextEncoding('UTF-8');
$canvas->annotateImage($draw, 196, 74, 0, subTextLength($info['nickname'],8));