php海报生成

这篇博客介绍了如何使用PHP进行海报生成的实现。通过代码示例,展示了具体的用法,帮助读者理解如何在PHP环境中创建和定制个性化海报。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

代码

composer require endroid/qr-code
<?php
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),imagesy
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值