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
@@ -37,41 +34,82 @@ composer require ibrand/laravel-miniprogram-poster
37
34
38
35
```
39
36
return [
40
- //图片存储位置
41
- 'disks' => [
42
- 'MiniProgramShare' => [
43
- 'driver' => 'local',
44
- 'root' => storage_path('app/public/share'),
45
- 'url' => env('APP_URL') . '/storage/share',
46
- 'visibility' => 'public',
47
- ],
48
- ],
49
- //图片宽度
50
- 'width' => '575px',
51
- //放大倍数
52
- 'zoomfactor' => 1.5,
53
- //0-100,100质量最高
54
- 'quality' => 100,
55
- //是否压缩图片
56
- 'compress' => true,
57
- ];
37
+ //图片存储位置
38
+ 'disks' => [
39
+ 'MiniProgramShare' => [
40
+ 'driver' => 'local',
41
+ 'root' => storage_path('app/public/share'),
42
+ 'url' => env('APP_URL') . '/storage/share',
43
+ 'visibility' => 'public',
44
+ ],
45
+ ],
46
+ //图片宽度
47
+ 'width' => '575px',
48
+ //放大倍数
49
+ 'zoomfactor' => 1.5,
50
+ //1-9,9质量最高
51
+ 'quality' => 9,
52
+ //是否压缩图片
53
+ 'compress' => true,
54
+ //是否删除废弃图片文件
55
+ 'delete'=>true,
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
-
64
- $url = 'https://www.ibrand.cc/';
72
+
73
+ 这个步骤通过 Laravel 路由视图来实现海报样式展示
74
+
75
+ ### 生成图片
76
+
77
+ 生成图片,不关联模型。
78
+
79
+ ``` php
80
+ $url = route('share.goods');
65
81
$result = MiniProgramShareImg::generateShareImage($url);
82
+ ```
83
+
84
+ ### 关联模型
66
85
86
+ 执行 命令生成 ` posters ` 表
67
87
```
68
- 返回结果:
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
+ ### 返回结果示例
69
105
```
70
106
[
71
107
'url' => 'http://xxx.png', 图片访问url
72
108
'path' => 'path/to/image', 图片文件路径
73
109
]
74
110
```
111
+
112
+
75
113
### 字体安装
76
114
77
115
如果需要实现复杂的字体效果,需要安装字体,比如在 centos 上就没有微软雅黑的字体,所以如果生成的图片有指定的特殊字体,需要在服务器上进行安装。
@@ -95,6 +133,10 @@ mkfontdir
95
133
fc-cache -fv
96
134
```
97
135
98
- ### Resource
136
+ ## Resource
99
137
100
138
项目基于[ PhantomMagick] ( https://github.com/anam-hossain/phantommagick )
139
+
140
+ ## 贡献源码
141
+
142
+ 如果你发现任何错误或者问题,请[ 提交ISSUE] ( https://github.com/ibrandcc/laravel-miniprogram-poster/issues )
0 commit comments