1 Star 0 Fork 64

mayun_drz / poster

forked from lang / poster 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

poster

介绍

基于gd库、phpqrcode

PHP海报生成插件,极速生成方便快捷。

快速生成海报、生成签到日、生成二维码、合成二维码、图片添加水印

提示:

1.新增批量处理方法

2.新增字体加粗参数

3.新增字体间隔参数

authors

lang 732853989@qq.com

安装或更新教程

  1. composer require kkokk/poster
  2. composer update kkokk/poster

使用说明

注意:没有特别说明,统一都是px。

文档地址:http://www.520yummy.com/composer/poster/doc.html

演示效果

输入图片说明

演示地址:暂无

​ 生成签到日历海报、邀请海报

引用海报类
use Kkokk\Poster\PosterManager;
use Kkokk\Poster\Exception\Exception;

$poster = PosterManager::Poster('poster/poster_user'); # 设置保存路径和文件名
创建画布
$poster->buildIm($w,$h,$rgba,$alpha); # 创建画布

参数说明

变量 类型 必填 注释
w number 画布宽
h number 画布高
rgba array 颜色rbga,[255,255,255,1]
alpha boolean 是否透明,是:true
创建指定图片为画布
$poster->buildImDst($src,$w,$h,$rgba,$alpha); # 创建指定图片为画布

参数说明

变量 类型 必填 注释
src source 图像资源
w number 画布宽,默认原图宽
h number 画布高,默认原图高
rgba array 颜色rbga,[255,255,255,1]
alpha boolean 是否透明,默认false
合成图片
$poster->buildImage($src,$dst_x,$dst_y,$src_x,$src_y,$src_w,$src_h,$alpha,$type); # 合成图片

参数说明

变量 类型 必填 注释
src string 路径,支持网络图片(带http或https)
dst_x number|string 目标x轴 特殊值 center 居中 支持百分比20% 支持自定义 支持正负
dst_y number|string 目标y轴 特殊值 center 居中 支持百分比20% 支持自定义 支持正负
src_x number 图片x轴,默认0
src_y number 图片y轴,默认0
src_w number 图片自定义宽,默认原宽
src_h number 图片自定义高,默认原高
alpha boolean 是否透明,true:是
type string 图片变形类型,正常形状:'normal',圆形:'circle' ,默认normal
批量合成图片
$images = [
    [
        'src'   => $src,
        'dst_x' => $dst_x,
        'dst_y' => $dst_y,
        'src_x' => $src_x,
        'src_y' => $src_y,
        'src_w' => $src_w,
        'src_h' => $src_h,
        'alpha' => $alpha,
        'type'  => $type
    ]
];
$poster->buildImageMany($images); # 批量合成图片

参数说明:与合成图片参数一致。

合成二维码
$poster->buildQr($text,$dst_x,$dst_y,$src_x,$src_y,$src_w,$src_h,$size,$margin); # 合成二维码

参数说明

变量 类型 必填 注释
text string 内容,例如:http://www.520yummy.com
dst_x number|string 画布位置x 特殊值 center 居中 支持百分比20% 支持自定义 支持正负
dst_y number|string 画布位置y 特殊值 center 居中 支持百分比20% 支持自定义 支持正负
src_x number 图片x轴,默认0
src_y number 图片y轴,默认0
src_w number 图片自定义宽,默认原宽
src_h number 图片自定义高,默认原高
alpha integer 大小,默认4
margin integer 白边大小,默认1
批量合成二维码
$qrs = [
    [
        'text'   => $text,
        'dst_x'  => $dst_x,
        'dst_y'  => $dst_y,
        'src_x'  => $src_x,
        'src_y'  => $src_y,
        'src_w'  => $src_w,
        'src_h'  => $src_h,
        'size'   => $size,
        'margin' => $margin
    ]
];
$poster->buildQrMany($qrs); # 批量合成二维码

参数说明:与合成二维码参数一致。

合成文字
$poster->buildText($content,$dst_x,$dst_y,$font,$rgba,$max_w,$font_family,$weight,$space); # 合成文字

参数说明

变量 类型 必填 注释
content string 内容,例如:http://www.520yummy.com
dst_x number|string|array 画布位置x ;特殊值 center 居中;居中并向左偏移 ['center',-5], 居中并向右偏移 ['center',5]
dst_y number 画布位置y,默认0
font number 字体大小,默认16
rgba number 颜色rbga,[255,255,255,1]
max_w number 最大换行宽度,默认0不换行。达到换行宽度自动换行
font_family number 字体,可不填,有默认 (相对路径为项目根目录)
weight integer 字体粗细 默认字体大小
space integer 字体间距 默认无
批量合成文字
$texts = [
    [
        'content'     => $content,
        'dst_x'       => $dst_x,
        'dst_y'       => $dst_y,
        'font'        => $font,
        'rgba'        => $rgba,
        'max_w'       => $max_w,
        'font_family' => $font_family,
        'weight'      => $weight,
        'space'       => $space
    ]
];
$poster->buildQrMany($texts); # 批量合成文字

参数说明:与合成文字参数一致。

获取海报
$poster->getPoster(); # 获取合成后图片文件地址

参数说明:无。

返回说明:返回数组,返回文件地址。

处理海报、图片
$poster->setPoster(); # 处理图片,需要传原图片

参数说明:无。

返回说明:处理原图片资源,无返回。

输出图片流
$poster->stream(); # 输出图片流

参数说明:无。

返回说明:返回文件流,可输出到浏览器或img标签。

生成二维码
$qr = PosterManager::Poster()->Qr('http://www.520yummy.com','poster/1.png'); # 生成二维码

参数说明

变量 类型 必填 注释
text string 二维码包含的内容,可以是链接、文字、json字符串等等,例如:http://www.520yummy.com
outfile boolean|string 默认为false,不生成文件,只将二维码图片返回输出;否则需要给出存放生成二维码图片的文件名及路径
level string 容错级别,默认为L, 可传递的值分别是L(QR_ECLEVEL_L,7%)、M(QR_ECLEVEL_M,15%)、Q(QR_ECLEVEL_Q,25%)、H(QR_ECLEVEL_H,30%)。这个参数控制二维码容错率,不同的参数表示二维码可被覆盖的区域百分比,也就是被覆盖的区域还能识别
size integer 控制生成图片的大小,默认为4
margin integer 控制生成二维码的空白区域大小,默认4
saveandprint boolean 保存二维码图片并显示出来,outfile 必须传递图片路径,默认false

返回说明:outfile 为空,输出二维码图片,不生成文件;否则返回图片路径。

示例

静态调用
use Kkokk\Poster\PosterManager;
use Kkokk\Poster\Exception\Exception;
# 合成图片
try {
    $addImage = "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2854425629,4097927492&fm=26&gp=0.jpg";
	$result = PosterManager::Poster('poster/poster_user') //生成海报,这里写保存路径和文件名,可以指定图片后缀。默认png
	->buildIm(638,826,[255,255,255,127],false)
	->buildImage('https://test.acyapi.51acy.com/wechat/poster/top_bg.png')
	->buildImage('https://test.acyapi.51acy.com/wechat/poster/half_circle.png',254,321)
	->buildImage($addImage,253,326,0,0,131,131,false,'circle')
	->buildImage('https://test.acyapi.51acy.com/wechat/poster/fengexian.png',0,655)
	->buildText('苏 轼','center',477,16,[51, 51, 51,1])
	->buildText('明月几时有,把酒问青天。不知天上宫阙,今夕是何年。','center',515,14,[53, 53, 53, 1])
	->buildText('我欲乘风归去,又恐琼楼玉宇,高处不胜寒。','center',535,14,[53, 153, 153, 1])
	->buildText('起舞弄清影,何似在人间。转朱阁,低绮户,照无眠。','center',555,14,[53, 153, 153, 1])
	->buildText('不应有恨,何事长向别时圆?','center',575,14,[53, 153, 153, 1])
	->buildText('人有悲欢离合,月有阴晴圆缺,此事古难全。','center',595,14,[53, 153, 153, 1])
	->buildText('但愿人长久,千里共婵娟。','center',615,14,[53, 153, 153, 1])
	->buildText('长按识别',497,720,15,[53, 153, 153, 1])
	->buildText('查看TA的更多作品',413,757,15,[53, 153, 153, 1])
	->buildQr('http://www.520yummy.com',37,692,0,0,0,0,4,1)
	->getPoster();

	# 批量合成
	$buildImageManyArr = [
		[
        	'src' => 'https://test.acyapi.51acy.com/wechat/poster/top_bg.png'
        ],
        [
            'src' => 'https://test.acyapi.51acy.com/wechat/poster/half_circle.png',
            'dst_x' => 254,
            'dst_y' => 321
        ],
        [
            'src' => 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2854425629,4097927492&fm=26&gp=0.jpg',
            'dst_x' => 253,
            'dst_y' => 326,
            'src_x' => 0,
            'src_y' => 0,
            'src_w' => 131,
            'src_h' => 131,
            'alpha' => false,
            'type'  => 'circle'
        ],
        [
            'src'   => 'https://test.acyapi.51acy.com/wechat/poster/fengexian.png',
            'dst_x' => 0,
            'dst_y' => 655
        ]
	];
	$buildTextManyArr  = [
		[
            'content'=> '苏轼',
            'dst_x' => 'center',
            'dst_y' => 477,
            'font' => 16,
            'rgba' => [51, 51, 51, 1],
            'max_w'=> 0,
            'font_family' => '',
            'weight' => 1,
            'space'=>20
        ],
        [
            'content'=> '明月几时有,把酒问青天。不知天上宫阙,今夕是何年。',
            'dst_x' => 'center',
            'dst_y' => 515,
            'font' => 16,
            'rgba' => [51, 51, 51, 1],
            'max_w'=> 0,
            'font_family' => '',
            'weight' => 1,
            'space'=>20
        ],
        [
            'content'=> '我欲乘风归去,又恐琼楼玉宇,高处不胜寒。',
            'dst_x' => 'center',
            'dst_y' => 535,
            'font' => 16,
            'rgba' => [51, 51, 51, 1],
            'max_w'=> 0,
            'font_family' => '',
            'weight' => 1,
            'space'=>20
        ],
        [
            'content'=> '起舞弄清影,何似在人间。转朱阁,低绮户,照无眠。',
            'dst_x' => 'center',
            'dst_y' => 555,
            'font' => 16,
            'rgba' => [51, 51, 51, 1],
            'max_w'=> 0,
            'font_family' => '',
            'weight' => 1,
            'space'=>20
        ],
        [
            'content'=> '不应有恨,何事长向别时圆?',
            'dst_x' => 'center',
            'dst_y' => 575,
            'font' => 16,
            'rgba' => [51, 51, 51, 1],
            'max_w'=> 0,
            'font_family' => '',
            'weight' => 1,
            'space'=>20
        ],
        [
            'content'=> '人有悲欢离合,月有阴晴圆缺,此事古难全。',
            'dst_x' => 'center',
            'dst_y' => 595,
            'font' => 16,
            'rgba' => [51, 51, 51, 1],
            'max_w'=> 0,
            'font_family' => '',
            'weight' => 1,
            'space'=>20
        ],
        [
            'content'=> '但愿人长久,千里共婵娟。',
            'dst_x' => 'center',
            'dst_y' => 615,
            'font' => 16,
            'rgba' => [51, 51, 51, 1],
            'max_w'=> 0,
            'font_family' => '',
            'weight' => 1,
            'space'=>20
        ],
        [
            'content'=> '长按识别',
            'dst_x' => 'center',
            'dst_y' => 720,
            'font' => 16,
            'rgba' => [51, 51, 51, 1],
            'max_w'=> 0,
            'font_family' => '',
            'weight' => 1,
            'space'=>20
        ],
        [
            'content'=> '查看TA的更多作品',
            'dst_x' => 'center',
            'dst_y' => 757,
            'font' => 16,
            'rgba' => [51, 51, 51, 1],
            'max_w'=> 0,
            'font_family' => '',
            'weight' => 1,
            'space'=>20
        ]
	];
	$buildQrManyArr    = [
		[
			'text'=>'http://www.520yummy.com',
            'dst_x'=>37,
            'dst_y'=>692,
            'src_x'=>0,
            'src_y'=>0,
            'src_w'=>0,
            'src_h'=>0,
            'size'=>4,
            'margin'=>1
		],
		[
			'text'=>'http://www.520yummy.com',
            'dst_x'=>74,
            'dst_y'=>692,
            'src_x'=>0,
            'src_y'=>0,
            'src_w'=>0,
            'src_h'=>0,
            'size'=>4,
            'margin'=>1
		]
	];

	$result = PosterManager::Poster('poster/poster_user')
	->buildIm(638,826,[255,255,255,127],false)
	->buildImageMany($buildImageManyArr)
	->buildTextMany($buildImageManyArr)
	->buildQrMany($buildQrManyArr)
	->getPoster();
    
    # 给图片添加水印
    $setImage = "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2854425629,4097927492&fm=26&gp=0.jpg";
	$result = PosterManager::Poster() //给指定图片添加水印,这里为空就好
	->buildImDst(__DIR__.'/test.jpeg')
	->buildImage($setImage,'-20%','-20%',0,0,0,0,false)
	->setPoster();

	# 生成二维码
	$result = PosterManager::Poster()->Qr('http://www.baidu.com','poster/1.png');
} catch (Exception $e){
	echo $e->getMessage();
}
实例化调用
use Kkokk\Poster\PosterManager;
use Kkokk\Poster\Exception\Exception;
# 合成图片
try {
    $addImage = "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2854425629,4097927492&fm=26&gp=0.jpg";
	$PosterManager = new PosterManager('poster/poster_user'); //生成海报,这里写保存路径和文件名,可以指定图片后缀。默认png
	$result = $PosterManager->buildIm(638,826,255,255,255,1]27,false)
	->buildIm(638,826,[255,255,255,127],false)
	->buildImage('https://test.acyapi.51acy.com/wechat/poster/top_bg.png')
	->buildImage('https://test.acyapi.51acy.com/wechat/poster/half_circle.png',254,321)
	->buildImage($addImage,253,326,0,0,131,131,false,'circle')
	->buildImage('https://test.acyapi.51acy.com/wechat/poster/fengexian.png',0,655)
	->buildText('苏 轼','center',477,16,[51, 51, 51,1])
	->buildText('明月几时有,把酒问青天。不知天上宫阙,今夕是何年。','center',515,14,[53, 53, 53, 1])
	->buildText('我欲乘风归去,又恐琼楼玉宇,高处不胜寒。','center',535,14,[53, 153, 153, 1])
	->buildText('起舞弄清影,何似在人间。转朱阁,低绮户,照无眠。','center',555,14,[53, 153, 153, 1])
	->buildText('不应有恨,何事长向别时圆?','center',575,14,[53, 153, 153, 1])
	->buildText('人有悲欢离合,月有阴晴圆缺,此事古难全。','center',595,14,[53, 153, 153, 1])
	->buildText('但愿人长久,千里共婵娟。','center',615,14,[53, 153, 153, 1])
	->buildText('长按识别',497,720,15,[53, 153, 153, 1])
	->buildText('查看TA的更多作品',413,757,15,[53, 153, 153, 1])
	->buildQr('http://www.520yummy.com',37,692,0,0,0,0,4,1)
	->getPoster();

	# 给图片添加水印
    $setImage = 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2854425629,4097927492&fm=26&gp=0.jpg';
	$PosterManager = new PosterManager(); //给指定图片添加水印,这里为空就好
	$result = $PosterManager->buildImDst(__DIR__.'/test.jpeg')
	->buildImage($setImage,'center','-20%',0,0,0,0,true)
	->setPoster();

	# 生成二维码
	$result = $PosterManager->Qr('http://www.baidu.com','poster/1.png');

} catch (Exception $e){
	echo $e->getMessage();
}
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

PHP海报生成插件,极速生成方便快捷。 快速生成海报、生成签到日历、生成二维码、合成二维码、图片添加水印、图片水印、水印 展开 收起
PHP
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
PHP
1
https://gitee.com/drz666/poster.git
git@gitee.com:drz666/poster.git
drz666
poster
poster
master

搜索帮助