php海报生成

代码

composer require endroid/qr-code

namespace App\Service;

use Endroid\QrCode\Builder\Builder;
use Endroid\QrCode\Color\Color;
use Endroid\QrCode\Encoding\Encoding;
use Endroid\QrCode\ErrorCorrectionLevel\ErrorCorrectionLevelHigh;
use Endroid\QrCode\RoundBlockSizeMode\RoundBlockSizeModeMargin;
use Endroid\QrCode\Writer\PngWriter;

class ImageService{
   

	public static function create($config = [], $filename = ''){
   
		$imageDefault = array(
			'left'    => 0,
			'top'     => 0,
			'width'   => 100,
			'height'  => 100,
			'opacity' => 100,
			'circle'  => 0
		);
		$qrcodeDefault = [
			'text'   => 'qrcode content',
			'size'   => 100,
			'margin' => 2,
			'left'   => 0,
			'top'    => 0,
			'color'  => '0,0,0'
		];
		$textDefault =  array(
			'text'      => '',
			'left'      => 0,
			'top'       => 0,
			'align'		=> '',
			'font-size' => 32,//字号
			'color'     => '0,0,0', //字体颜色
			'angle'     => 0,
			'font-path'  => RUNTIME_PATH . '/font/SourceHanSansCN-Regular.otf' //字体
		);

		$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);

		//imageColorTransparent($imageRes, $color);    //颜色透明

		imagecopyresampled($imageRes,$background,0,0,0,0,imagesx($background),imagesy($background),imagesx($background),

你可能感兴趣的:(PHP,php)