Skip to content

Commit d20cf96

Browse files
committed
Merge branch '2.x'
# Conflicts: # README.md
2 parents e4de616 + 84bee8c commit d20cf96

11 files changed

+437
-111
lines changed

README.md

Lines changed: 76 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,30 @@
11
# Laravel 小程序图文海报生成包
22

3-
微信小程序中生成朋友圈分享图文海报的一种解决方案
3+
微信小程序中生成朋友圈分享图文海报一种可以实际使用的解决方案
44

55
[![Build Status](https://travis-ci.org/ibrandcc/laravel-miniprogram-poster.svg?branch=master)](https://travis-ci.org/ibrandcc/laravel-miniprogram-poster)
66
[![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)
77
[![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)
88
[![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)
99

10-
## Featrue
10+
## 特性
1111

12-
1. 基于html可实现复杂的文字,图片,阴影效果。
12+
1. 基于 html 可实现复杂的文字,图片,阴影效果。
1313
2. 清晰度和文件大小合理
1414
3. 使用简单、即插即用
15-
16-
## TODO:
17-
18-
1. 存储 Model 对象和图片对应关系,避免重复生成图片。
15+
4. 存储 Model 对象和图片对应关系,避免重复生成图片。
1916

2017
## 体验
2118

2219
扫码进入商品详情页分享生成图文体验
2320

2421
![iBrand开源体验店](https://iyoyo.oss-cn-hangzhou.aliyuncs.com/post/miniprogramcode/1.jpg)
2522

26-
### 安装
23+
## 安装
2724
```
28-
composer require ibrand/laravel-miniprogram-poster
25+
composer require ibrand/laravel-miniprogram-poster:~2.0 -vvv
2926
```
30-
- 低于 Laravel5.5 版本,`config/app.php` 文件中 'providers' 添加`iBrand\Poster\PhantoMmagickServiceProvider::class`
27+
- 低于 Laravel5.5 版本,`config/app.php` 文件中 `providers` 添加`iBrand\Poster\PhantoMmagickServiceProvider::class`
3128

3229
- 图片保存在 `storage/app/public` 下所以需要执行 `php artisan storage:link`
3330

@@ -37,41 +34,82 @@ composer require ibrand/laravel-miniprogram-poster
3734

3835
```
3936
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+
];
5857
```
5958

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+
}
6171
```
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');
6581
$result = MiniProgramShareImg::generateShareImage($url);
82+
```
83+
84+
### 关联模型
6685

86+
执行 命令生成 `posters`
6787
```
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+
### 返回结果示例
69105
```
70106
[
71107
'url' => 'http://xxx.png', 图片访问url
72108
'path' => 'path/to/image', 图片文件路径
73109
]
74110
```
111+
112+
75113
### 字体安装
76114

77115
如果需要实现复杂的字体效果,需要安装字体,比如在 centos 上就没有微软雅黑的字体,所以如果生成的图片有指定的特殊字体,需要在服务器上进行安装。
@@ -95,6 +133,10 @@ mkfontdir
95133
fc-cache -fv
96134
```
97135

98-
### Resource
136+
## Resource
99137

100138
项目基于[PhantomMagick](https://github.com/anam-hossain/phantommagick)
139+
140+
## 贡献源码
141+
142+
如果你发现任何错误或者问题,请[提交ISSUE](https://github.com/ibrandcc/laravel-miniprogram-poster/issues)

config/config.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
'width' => '575px',
2424
//放大倍数
2525
'zoomfactor' => 1.5,
26-
//0-100,100质量最高
27-
'quality' => 100,
26+
//1-9,9质量最高
27+
'quality' => 9,
2828
//是否压缩图片
2929
'compress' => true,
30+
//是否删除废弃图片文件
31+
'delete'=>true,
3032
];
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
use Illuminate\Support\Facades\Schema;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Database\Migrations\Migration;
6+
7+
class CreatePosterTables extends Migration
8+
{
9+
public function up()
10+
{
11+
if (!Schema::hasTable('posters')) {
12+
Schema::create('posters', function (Blueprint $table) {
13+
$table->increments('id');
14+
$table->text('content')->nullable();
15+
$table->integer('posterable_id')->unsigned();
16+
$table->string('posterable_type');
17+
$table->timestamps();
18+
$table->index(['posterable_id', 'posterable_type']);
19+
});
20+
}
21+
}
22+
23+
public function down()
24+
{
25+
Schema::dropIfExists('posters');
26+
}
27+
}

src/HasPoster.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/*
4+
* This file is part of ibrand/laravel-miniprogram-poster.
5+
*
6+
* (c) iBrand <https://www.ibrand.cc>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace iBrand\Miniprogram\Poster;
13+
14+
trait HasPoster
15+
{
16+
public function posters()
17+
{
18+
return $this->morphMany(Poster::class, 'posterable');
19+
}
20+
}

0 commit comments

Comments
 (0)