Extension.php
2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
/**
* Author: lang
* Email: 732853989@qq.com
* Date: 2023/3/22
* Time: 18:01
*/
namespace Kkokk\Poster\Image;
use Kkokk\Poster\Exception\PosterException;
class Extension implements ExtensionInterface
{
protected $driver;
protected $path;
function __construct($driver, $path)
{
$this->driver = $driver;
$this->path = $path;
}
public function config($params = [])
{
return $this->query()->config($params);
}
public function buildIm($w, $h, $rgba = [], $alpha = false)
{
return $this->query()->buildIm($w, $h, $rgba, $alpha);
}
public function buildImDst($src, $w = 0, $h = 0)
{
return $this->query()->buildImDst($src, $w, $h);
}
public function buildBg($w, $h, $rgba = [], $alpha = false, $dst_x = 0, $dst_y = 0, $src_x = 0, $src_y = 0, \Closure $callback = null)
{
return $this->query()->buildBg($w, $h, $rgba, $alpha, $dst_x, $dst_y, $src_x, $src_y, $callback);
}
public function Qr($text, $outfile = false, $level = 'L', $size = 4, $margin = 1, $saveAndPrint = 0)
{
return $this->getDriverInstance()->createQr($text, $outfile, $level, $size, $margin, $saveAndPrint);
}
public function getPoster($query, $path)
{
return $this->getDriverInstance($query)->getData($path);
}
public function setPoster($query)
{
return $this->getDriverInstance($query)->setData();
}
public function stream($query)
{
return $this->getDriverInstance($query)->getStream();
}
public function baseData($query)
{
return $this->getDriverInstance($query)->getBaseData();
}
public function query()
{
return new Builder(
$this,
$this->getQueryInstance(),
$this->path
);
}
/**
* Author: lang
* Email: 732853989@qq.com
* Date: 2023/3/24
* Time: 15:45
* @param $query
* @return \Kkokk\Poster\Image\Drivers\Driver
* @throws PosterException
*/
protected function getDriverInstance($query = [])
{
return $this->run($query, function ($query) {
return $this->driver->execute($query);
});
}
protected function run($query, \Closure $callback)
{
try {
$result = $callback($query);
} catch (\Exception $e) {
throw new PosterException($e->getMessage(), 0, $e);
}
return $result;
}
}