Skip to content

Commit 8ea9874

Browse files
committed
FIX CS.
1 parent 251a929 commit 8ea9874

File tree

3 files changed

+114
-89
lines changed

3 files changed

+114
-89
lines changed

config/config.php

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
<?php
22

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+
312
return [
4-
//图片存储位置
5-
'disks' => [
6-
'MiniProgramShare' => [
7-
'driver' => 'local',
8-
'root' => storage_path('app/public/share'),
9-
'url' => env('APP_URL') . '/storage/share',
10-
'visibility' => 'public',
11-
],
12-
],
13-
'directory' => 'travel',
14-
//图片宽度
15-
'width' => '575',
16-
//放大倍数
17-
'zoomfactor' => 1.5,
18-
//0-100,100质量最高
19-
'quality' => 100,
20-
//是否压缩图片
21-
'compress' => true,
22-
];
13+
//图片存储位置
14+
'disks' => [
15+
'MiniProgramShare' => [
16+
'driver' => 'local',
17+
'root' => storage_path('app/public/share'),
18+
'url' => env('APP_URL').'/storage/share',
19+
'visibility' => 'public',
20+
],
21+
],
22+
'directory' => 'travel',
23+
//图片宽度
24+
'width' => '575',
25+
//放大倍数
26+
'zoomfactor' => 1.5,
27+
//0-100,100质量最高
28+
'quality' => 100,
29+
//是否压缩图片
30+
'compress' => true,
31+
];

src/MiniProgramShareImg.php

Lines changed: 65 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,74 @@
11
<?php
22

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+
312
namespace iBrand\Miniprogram\Poster;
413

514
use Anam\PhantomMagick\Converter;
615
use Storage;
716

817
class MiniProgramShareImg
918
{
10-
public static $conv = null;
11-
12-
public static function init()
13-
{
14-
if (is_null(self::$conv) || !self::$conv instanceof Converter) {
15-
self::$conv = new Converter();
16-
}
17-
18-
return self::$conv;
19-
}
20-
21-
public static function generateShareImage($route)
22-
{
23-
if (!$route) {
24-
return false;
25-
}
26-
27-
$options = [
28-
'dimension' => config('ibrand.miniprogram-poster.width', '575px'),
29-
'zoomfactor' => config('ibrand.miniprogram-poster.zoomfactor', 1.5),
30-
'quality' => config('ibrand.miniprogram-poster.quality', 100),
31-
];
32-
33-
$saveName = config('ibrand.miniprogram-poster.directory') . '/' . md5(uniqid()) . '.png';
34-
$root = config('ibrand.miniprogram-poster.disks.MiniProgramShare.root');
35-
$file = $root . '/' . $saveName;
36-
37-
try {
38-
$converter = self::init();
39-
40-
$converter->source($route)->toPng($options)->save($file);
41-
42-
if (config('ibrand.miniprogram-poster.compress', true)) {
43-
self::imagePngSizeAdd($file);
44-
}
45-
46-
return Storage::disk('MiniProgramShare')->url($saveName);
47-
48-
} catch (\Exception $exception) {
49-
50-
return false;
51-
}
52-
}
53-
54-
public static function imagePngSizeAdd($file)
55-
{
56-
list($width, $height, $type) = getimagesize($file);
57-
$new_width = $width * 1;
58-
$new_height = $height * 1;
59-
60-
//header('Content-Type:image/png');
61-
$resource = imagecreatetruecolor($new_width, $new_height);
62-
$image = imagecreatefrompng($file);
63-
imagecopyresampled($resource, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
64-
imagejpeg($resource, $file, config('ibrand.miniprogram-poster.quality'));
65-
imagedestroy($resource);
66-
}
67-
}
19+
public static $conv = null;
20+
21+
public static function init()
22+
{
23+
if (is_null(self::$conv) || !self::$conv instanceof Converter) {
24+
self::$conv = new Converter();
25+
}
26+
27+
return self::$conv;
28+
}
29+
30+
public static function generateShareImage($route)
31+
{
32+
if (!$route) {
33+
return false;
34+
}
35+
36+
$options = [
37+
'dimension' => config('ibrand.miniprogram-poster.width', '575px'),
38+
'zoomfactor' => config('ibrand.miniprogram-poster.zoomfactor', 1.5),
39+
'quality' => config('ibrand.miniprogram-poster.quality', 100),
40+
];
41+
42+
$saveName = config('ibrand.miniprogram-poster.directory').'/'.md5(uniqid()).'.png';
43+
$root = config('ibrand.miniprogram-poster.disks.MiniProgramShare.root');
44+
$file = $root.'/'.$saveName;
45+
46+
try {
47+
$converter = self::init();
48+
49+
$converter->source($route)->toPng($options)->save($file);
50+
51+
if (config('ibrand.miniprogram-poster.compress', true)) {
52+
self::imagePngSizeAdd($file);
53+
}
54+
55+
return Storage::disk('MiniProgramShare')->url($saveName);
56+
} catch (\Exception $exception) {
57+
return false;
58+
}
59+
}
60+
61+
public static function imagePngSizeAdd($file)
62+
{
63+
list($width, $height, $type) = getimagesize($file);
64+
$new_width = $width * 1;
65+
$new_height = $height * 1;
66+
67+
//header('Content-Type:image/png');
68+
$resource = imagecreatetruecolor($new_width, $new_height);
69+
$image = imagecreatefrompng($file);
70+
imagecopyresampled($resource, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
71+
imagejpeg($resource, $file, config('ibrand.miniprogram-poster.quality'));
72+
imagedestroy($resource);
73+
}
74+
}
Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
<?php
22

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+
312
namespace iBrand\Miniprogram\Poster;
413

514
use Illuminate\Support\ServiceProvider;
615

716
class PhantoMmagickServiceProvider extends ServiceProvider
817
{
9-
public function boot()
10-
{
11-
if ($this->app->runningInConsole()) {
12-
$this->publishes([__DIR__ . '/../config/config.php' => config_path('ibrand/miniprogram-poster.php')], 'config');
13-
}
14-
}
18+
public function boot()
19+
{
20+
if ($this->app->runningInConsole()) {
21+
$this->publishes([__DIR__.'/../config/config.php' => config_path('ibrand/miniprogram-poster.php')], 'config');
22+
}
23+
}
1524

16-
public function register()
17-
{
18-
$filesystems = $this->app['config']->get('filesystems.disks', []);
25+
public function register()
26+
{
27+
$filesystems = $this->app['config']->get('filesystems.disks', []);
1928

20-
$this->app['config']->set('filesystems.disks', array_merge(config('ibrand.miniprogram-poster.disks', []), $filesystems));
21-
}
22-
}
29+
$this->app['config']->set('filesystems.disks', array_merge(config('ibrand.miniprogram-poster.disks', []), $filesystems));
30+
}
31+
}

0 commit comments

Comments
 (0)