1
1
# Laravel 小程序图文海报生成包
2
2
3
- 微信小程序中生成朋友圈分享图文海报的一种解决方案
3
+ 微信小程序中生成朋友圈分享图文海报一种可以实际使用的解决方案
4
4
5
5
[ ![ Build Status] ( https://travis-ci.org/ibrandcc/laravel-miniprogram-poster.svg?branch=master )] ( https://travis-ci.org/ibrandcc/laravel-miniprogram-poster )
6
6
[ ![ Scrutinizer Code Quality] ( https://scrutinizer-ci.com/g/ibrandcc/laravel-miniprogram-poster/badges/quality-score.png?b=master )] ( https://scrutinizer-ci.com/g/ibrandcc/laravel-miniprogram-poster/?branch=master )
7
7
[ ![ Code Coverage] ( https://scrutinizer-ci.com/g/ibrandcc/laravel-miniprogram-poster/badges/coverage.png?b=master )] ( https://scrutinizer-ci.com/g/ibrandcc/laravel-miniprogram-poster/?branch=master )
8
8
[ ![ Build Status] ( https://scrutinizer-ci.com/g/ibrandcc/laravel-miniprogram-poster/badges/build.png?b=master )] ( https://scrutinizer-ci.com/g/ibrandcc/laravel-miniprogram-poster/build-status/master )
9
9
10
- ## Featrue
10
+ ## 特性
11
11
12
- 1 . 基于html可实现复杂的文字 ,图片,阴影效果。
12
+ 1 . 基于 html 可实现复杂的文字 ,图片,阴影效果。
13
13
2 . 清晰度和文件大小合理
14
14
3 . 使用简单、即插即用
15
-
16
- ## TODO:
17
-
18
- 1 . 存储 Model 对象和图片对应关系,避免重复生成图片。
15
+ 4 . 存储 Model 对象和图片对应关系,避免重复生成图片。
19
16
20
17
## 体验
21
18
22
19
扫码进入商品详情页分享生成图文体验
23
20
24
21
![ iBrand开源体验店] ( https://iyoyo.oss-cn-hangzhou.aliyuncs.com/post/miniprogramcode/1.jpg )
25
22
26
- ### 安装
23
+ ## 安装
27
24
```
28
- composer require ibrand/laravel-miniprogram-poster
25
+ composer require ibrand/laravel-miniprogram-poster:~2.0 -vvv
29
26
```
30
- - 低于 Laravel5.5 版本,` config/app.php ` 文件中 ' providers' 添加` iBrand\Poster\PhantoMmagickServiceProvider::class `
27
+ - 低于 Laravel5.5 版本,` config/app.php ` 文件中 ` providers ` 添加` iBrand\Poster\PhantoMmagickServiceProvider::class `
31
28
32
29
- 图片保存在 ` storage/app/public ` 下所以需要执行 ` php artisan storage:link `
33
30
@@ -54,27 +51,65 @@ composer require ibrand/laravel-miniprogram-poster
54
51
'quality' => 9,
55
52
//是否压缩图片
56
53
'compress' => true,
54
+ //是否删除废弃图片文件
55
+ 'delete'=>true,
57
56
];
58
57
```
59
58
60
- ### 使用
59
+ ## 使用
60
+
61
+ ### 定义路由和视图
62
+
63
+ ``` php
64
+ Router::get('share/goods','ShareController@goods')->name('share.goods');
65
+
66
+ public function goods()
67
+ {
68
+ //你的业务逻辑代码,获取到相关数据
69
+ return view('share.goods',compact('data'));
70
+ }
61
71
```
62
- use iBrand\Miniprogram\Poster\MiniProgramShareImg;
63
- use iBrand\Miniprogram\Poster\Poster;
64
-
65
- config(['ibrand.miniprogram-poster.width' => '1300px']);
66
- $url = 'https://www.ibrand.cc/';
67
- $goods = GoodsTestModel::find(1);
68
- $result = MiniProgramShareImg::run($goods, $url);
69
72
73
+ 这个步骤通过 Laravel 路由视图来实现海报样式展示
74
+
75
+ ### 生成图片
76
+
77
+ 生成图片,不关联模型。
78
+
79
+ ``` php
80
+ $url = route('share.goods');
81
+ $result = MiniProgramShareImg::generateShareImage($url);
82
+ ```
83
+
84
+ ### 关联模型
85
+
86
+ 执行 命令生成 ` posters ` 表
70
87
```
71
- 返回结果:
88
+ php artisan vendor:publish
89
+ php artisan migrate
90
+ ```
91
+
92
+ 生成图片并关联模型
93
+ ``` php
94
+ $goods = Goods::find(1);
95
+ $result = MiniProgramShareImg::run($goods, $url);
96
+ ```
97
+ 生成图片、关联模型并且重新生成图片
98
+ ``` php
99
+ $goods = Goods::find(1);
100
+ $result = MiniProgramShareImg::run($goods, $url,true);
101
+ ```
102
+
103
+
104
+ ### 返回结果示例
72
105
```
73
106
[
74
107
'url' => 'http://xxx.png', 图片访问url
75
108
'path' => 'path/to/image', 图片文件路径
76
109
]
77
110
```
111
+
112
+
78
113
### 字体安装
79
114
80
115
如果需要实现复杂的字体效果,需要安装字体,比如在 centos 上就没有微软雅黑的字体,所以如果生成的图片有指定的特殊字体,需要在服务器上进行安装。
@@ -98,6 +133,10 @@ mkfontdir
98
133
fc-cache -fv
99
134
```
100
135
101
- ### Resource
136
+ ## Resource
102
137
103
138
项目基于[ PhantomMagick] ( https://github.com/anam-hossain/phantommagick )
139
+
140
+ ## 贡献源码
141
+
142
+ 如果你发现任何错误或者问题,请[ 提交ISSUE] ( https://github.com/ibrandcc/laravel-miniprogram-poster/issues )
0 commit comments