GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#28)
by t
02:46 queued 27s
created

Image::__destruct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
1
<?php
2
/**
3
 * Class Image
4
 *
5
 * @link https://www.icy2003.com/
6
 * @author icy2003 <[email protected]>
7
 * @copyright Copyright (c) 2017, icy2003
8
 */
9
namespace icy2003\php\ihelpers;
10
11
use Exception;
12
use icy2003\php\C;
13
use icy2003\php\I;
14
15
/**
16
 * 图片处理类
17
 */
18
class Image
19
{
20
21
    /**
22
     * 加载图片
23
     *
24
     * @param string $image 图片路径
25
     *
26
     * @return void
27
     */
28
    public function __construct($image)
29
    {
30
        $this->_attributes = $this->__parseImage($image);
31
        $this->_imageIn = $this->_attributes['object'];
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->_attributes['object'] can also be of type false. However, the property $_imageIn is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
32
    }
33
34
    /**
35
     * 输入图片对象
36
     *
37
     * @var resource
38
     */
39
    protected $_imageIn;
40
41
    /**
42
     * 输出图片对象
43
     *
44
     * @var resource
45
     */
46
    protected $_imageOut;
47
48
    /**
49
     * 图片属性
50
     *
51
     * @var array
52
     */
53
    protected $_attributes = [];
54
55
    /**
56
     * 解析图片属性
57
     *
58
     * @param string $image 图片地址
59
     *
60
     * @return array
61
     */
62
    private function __parseImage($image)
63
    {
64
        $image = I::getAlias($image);
65
        C::assertTrue(is_array($size = @getimagesize($image)), '不是有效的图片:' . $image);
66
        // static::$_instance->_attributes['size'] = $size;
67
        $width = $size[0];
68
        $height = $size[1];
69
        $mime = $size['mime'];
70
        switch ($size[2]) {
71
            case 1:
72
                $ext = 'gif';
73
                $object = imagecreatefromgif($image);
74
                $method = 'imagegif';
75
                break;
76
            case 2:
77
                $ext = 'jpg';
78
                $object = imagecreatefromjpeg($image);
79
                $method = 'imagejpeg';
80
                break;
81
            case 3:
82
                $ext = 'png';
83
                $object = imagecreatefrompng($image);
84
                $method = 'imagepng';
85
                break;
86
            default:
87
                throw new Exception("不支持的图片类型");
88
        }
89
        return [
90
            'file' => $image,
91
            'width' => $width,
92
            'height' => $height,
93
            'mime' => $mime,
94
            'ext' => $ext,
95
            'object' => $object,
96
            'method' => $method,
97
        ];
98
    }
99
100
    /**
101
     * 获取图片属性数组
102
     *
103
     * @return array
104
     */
105
    public function getAttributes()
106
    {
107
        return $this->_attributes;
108
    }
109
110
    /**
111
     * 获取图片属性
112
     *
113
     * @param string $name
114
     *
115
     * @return mixed
116
     */
117
    public function getAttribute($name)
118
    {
119
        return I::get($this->_attributes, $name);
120
    }
121
122
    /**
123
     * 设置透明度
124
     *
125
     * @return void
126
     */
127
    private function __setTransparency()
128
    {
129
        $index = imagecolortransparent($this->_imageIn);
130
        $color = ['red' => 255, 'green' => 255, 'blue' => 255];
131
        if ($index >= 0) {
132
            $color = imagecolorsforindex($this->_imageIn, $index);
133
        }
134
        null === $this->_imageOut && $this->_imageOut = imagecreatetruecolor($this->_attributes['width'], $this->_attributes['height']);
0 ignored issues
show
Documentation Bug introduced by
It seems like imagecreatetruecolor($th...>_attributes['height']) can also be of type false. However, the property $_imageOut is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
135
        $index = imagecolorallocate($this->_imageOut, $color['red'], $color['green'], $color['blue']);
0 ignored issues
show
Bug introduced by
It seems like $this->_imageOut can also be of type false; however, parameter $image of imagecolorallocate() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

135
        $index = imagecolorallocate(/** @scrutinizer ignore-type */ $this->_imageOut, $color['red'], $color['green'], $color['blue']);
Loading history...
136
        imagefill($this->_imageOut, 0, 0, $index);
0 ignored issues
show
Bug introduced by
It seems like $this->_imageOut can also be of type false; however, parameter $image of imagefill() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

136
        imagefill(/** @scrutinizer ignore-type */ $this->_imageOut, 0, 0, $index);
Loading history...
137
        imagecolortransparent($this->_imageOut, $index);
0 ignored issues
show
Bug introduced by
It seems like $this->_imageOut can also be of type false; however, parameter $image of imagecolortransparent() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

137
        imagecolortransparent(/** @scrutinizer ignore-type */ $this->_imageOut, $index);
Loading history...
138
    }
139
140
    /**
141
     * 缩放图片
142
     *
143
     * @param array|integer $zoom 数组或数字,如:数组[1, 0.5]表示宽不变,高变成一半,如果是整数,表示等比例缩放
144
     *
145
     * @return static
146
     */
147
    public function zoom($zoom = 1)
148
    {
149
        if (2 === Arrays::count($zoom)) {
150
            list($zoomWidth, $zoomHeight) = $zoom;
151
            $zoomWidth *= $this->_attributes['width'];
152
            $zoomHeight *= $this->_attributes['height'];
153
        } else {
154
            $zoom = (int) $zoom;
155
            $zoomWidth = $zoom * $this->_attributes['width'];
156
            $zoomHeight = $zoom * $this->_attributes['height'];
157
        }
158
        if ($this->_imageOut = imagecreatetruecolor($zoomWidth, $zoomHeight)) {
0 ignored issues
show
Documentation Bug introduced by
It seems like imagecreatetruecolor($zoomWidth, $zoomHeight) can also be of type false. However, the property $_imageOut is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
159
            $this->__setTransparency();
160
            imagecopyresampled($this->_imageOut, $this->_imageIn, 0, 0, 0, 0, $zoomWidth, $zoomHeight, $this->_attributes['width'], $this->_attributes['height']);
161
        }
162
163
        return $this;
164
    }
165
166
    /**
167
     * 裁剪
168
     *
169
     * @param array $cut 裁剪的宽高,如:[100, 200]
170
     * @param array $pos 裁剪起始 x 和 y 坐标,坐标原点在左上角,如:[0, 0]
171
     *
172
     * @return static
173
     */
174
    public function cut($cut = null, $pos = [0, 0])
175
    {
176
        null === $cut && $cut = [$this->_attributes['width'], $this->_attributes['height']];
177
        $width = min($this->_attributes['width'], $cut[0]);
178
        $height = min($this->_attributes['height'], $cut[1]);
179
        $x = min($this->_attributes['width'], $pos[0]);
180
        $y = min($this->_attributes['height'], $pos[1]);
181
        if ($this->_imageOut = imagecreatetruecolor($width, $height)) {
0 ignored issues
show
Documentation Bug introduced by
It seems like imagecreatetruecolor($width, $height) can also be of type false. However, the property $_imageOut is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
182
            $this->__setTransparency();
183
            imagecopy($this->_imageOut, $this->_imageIn, 0, 0, $x, $y, $this->_attributes['width'], $this->_attributes['height']);
184
        }
185
186
        return $this;
187
    }
188
189
    /**
190
     * 创建文字水印
191
     *
192
     * @param string $text 文字水印内容
193
     * @param array $pos 水印位置,默认在左上角的坐标原点
194
     * @param mixed $fontColor 颜色值,支持类型参见 Color
195
     * @param int $fontSize 字体大小,默认 12
196
     * @param string $fontPath 字体路径,默认宋体
197
     *
198
     * @return static
199
     */
200
    public function markText($text, $pos = [0, 0], $fontColor = 'black', $fontSize = 12, $fontPath = 'simkai')
201
    {
202
        if ($this->_imageOut = imagecreatetruecolor($this->_attributes['width'], $this->_attributes['height'])) {
0 ignored issues
show
Documentation Bug introduced by
It seems like imagecreatetruecolor($th...>_attributes['height']) can also be of type false. However, the property $_imageOut is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
203
            $this->__setTransparency();
204
            $text = Charset::toUtf($text);
205
            $temp = imagettfbbox($fontSize, 0, $fontPath, $text);
206
            $textWidth = $temp[2] - $temp[6];
207
            // $textHeight = $temp[3] - $temp[7];
208
            imagesettile($this->_imageOut, $this->_imageIn);
209
            imagefilledrectangle($this->_imageOut, 0, 0, $this->_attributes['width'], $this->_attributes['height'], IMG_COLOR_TILED);
210
            list($red, $green, $blue) = (new Color($fontColor))->toRGB()->get();
211
            $text2 = imagecolorallocate($this->_imageOut, $red, $green, $blue);
212
            $posX = min($pos[0], $this->_attributes['width'] - $textWidth);
213
            $posY = min($pos[1], $this->_attributes['height']);
214
            imagettftext($this->_imageOut, $fontSize, 0, $posX, $posY, $text2, $fontPath, $text);
215
        }
216
217
        return $this;
218
    }
219
220
    /**
221
     * 创建图片水印
222
     *
223
     * @param string $image 图片水印的地址
224
     * @param array $pos 水印位置,默认在左上角的坐标原点
225
     * @param array $size 图片水印大小,如果不给则是默认大小
226
     *
227
     * @return static
228
     */
229
    public function markPicture($image, $pos = [0, 0], $size = null)
230
    {
231
        if ($this->_imageOut = imagecreatetruecolor($this->_attributes['width'], $this->_attributes['height'])) {
0 ignored issues
show
Documentation Bug introduced by
It seems like imagecreatetruecolor($th...>_attributes['height']) can also be of type false. However, the property $_imageOut is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
232
            $this->__setTransparency();
233
            $markAttrs = $this->__parseImage($image);
234
            null === $size && $size = [$markAttrs['width'], $markAttrs['height']];
235
            imagecopy($this->_imageOut, $this->_imageIn, 0, 0, 0, 0, $this->_attributes['width'], $this->_attributes['height']);
236
            $posX = min($pos[0], $this->_attributes['width'] - $size[0]);
237
            $posY = min($pos[1], $this->_attributes['height'] - $size[1]);
238
            imagecopyresized($this->_imageOut, /** @scrutinizer ignore-type */$markAttrs['object'], $posX, $posY, 0, 0, $size[0], $size[1], $markAttrs['width'], $markAttrs['height']);
239
            imagedestroy(/** @scrutinizer ignore-type */$markAttrs['object']);
240
        }
241
242
        return $this;
243
    }
244
245
    /**
246
     * 沿着 Y 轴翻转
247
     *
248
     * @return static
249
     */
250
    public function turnY()
251
    {
252
        if ($this->_imageOut = imagecreatetruecolor($this->_attributes['width'], $this->_attributes['height'])) {
0 ignored issues
show
Documentation Bug introduced by
It seems like imagecreatetruecolor($th...>_attributes['height']) can also be of type false. However, the property $_imageOut is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
253
            for ($x = 0; $x < $this->_attributes['width']; $x++) {
254
                imagecopy($this->_imageOut, $this->_imageIn, $this->_attributes['width'] - $x - 1, 0, $x, 0, 1, $this->_attributes['height']);
255
            }
256
        }
257
258
        return $this;
259
    }
260
261
    /**
262
     * 沿着 X 轴翻转
263
     *
264
     * @return static
265
     */
266
    public function turnX()
267
    {
268
        if ($this->_imageOut = imagecreatetruecolor($this->_attributes['width'], $this->_attributes['height'])) {
0 ignored issues
show
Documentation Bug introduced by
It seems like imagecreatetruecolor($th...>_attributes['height']) can also be of type false. However, the property $_imageOut is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
269
            for ($y = 0; $y < $this->_attributes['height']; $y++) {
270
                imagecopy($this->_imageOut, $this->_imageIn, 0, $this->_attributes['height'] - $y - 1, 0, $y, $this->_attributes['width'], 1);
271
            }
272
        }
273
274
        return $this;
275
    }
276
277
    /**
278
     * 逆时针旋转图片
279
     *
280
     * @param integer $degrees 角度
281
     *
282
     * @return static
283
     */
284
    public function rotate($degrees = -90)
285
    {
286
        $this->_imageOut = imagerotate($this->_attributes['object'], $degrees, 0);
0 ignored issues
show
Documentation Bug introduced by
It seems like imagerotate($this->_attr...'object'], $degrees, 0) can also be of type false. However, the property $_imageOut is declared as type resource. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
287
        $this->__setTransparency();
288
289
        return $this;
290
    }
291
292
    /**
293
     * 获取 (x, y) 坐标处的颜色值
294
     *
295
     * @param integer $x
296
     * @param integer $y
297
     *
298
     * @return \icy2003\php\ihelpers\Color Color 类对象
299
     */
300
    public function getColor($x, $y){
301
        $rgb = imagecolorat($this->_attributes['object'], $x, $y);
302
        return new Color([($rgb >> 16) & 0xFF, ($rgb >> 8) & 0xFF, $rgb & 0xFF], Color::TYPE_RGB);
303
    }
304
305
    /**
306
     * 保存图片到某个路径下,文件名自动生成
307
     *
308
     * @param string $path 目标路径
309
     *
310
     * @return void
311
     */
312
    public function saveTo($path = './')
313
    {
314
        $this->save($path . date('YmdHis') . '.' . $this->_attributes['ext']);
315
    }
316
317
    /**
318
     * 保存到文件,如果不给文件名,则保存回原文件
319
     *
320
     * @return void
321
     */
322
    public function save($file = null)
323
    {
324
        null === $file && $file = $this->_attributes['file'];
325
        $this->_attributes['out'] = $file;
326
        $method = $this->_attributes['method'];
327
        $method($this->_imageOut, $this->_attributes['out']);
328
    }
329
330
    /**
331
     * 显示图片到浏览器
332
     *
333
     * @return void
334
     */
335
    public function show()
336
    {
337
        header('Content-type:' . $this->_attributes['mime']);
338
        $method = $this->_attributes['method'];
339
        null === $this->_imageOut && $this->_imageOut = $this->_imageIn;
340
        $method($this->_imageOut);
341
    }
342
343
    /**
344
     * 释放图片资源
345
     *
346
     * @return void
347
     */
348
    public function destroy()
349
    {
350
        is_resource($this->_imageIn) && imagedestroy($this->_imageIn);
351
        is_resource($this->_imageOut) && imagedestroy($this->_imageOut);
352
    }
353
354
    /**
355
     * 生成验证码
356
     *
357
     * @todo 智能处理文字和图片间距大小等
358
     *
359
     * @param string $code 验证码
360
     * @param array $size 验证码图片宽高,默认 80*30
361
     * @param int $fontSize 字体大小,默认 14
362
     * @param string $fontPath 字体路径,默认宋体
363
     * @param int $pixelNum 杂点数量,默认 2
364
     * @param int $pixelColor 杂点颜色数量,默认 5
365
     * @param int $padding 文字左右间距
366
     * @param int $margin 文字左边距
367
     * @param int $base 文字上边距
368
     * @param int $baseOffset 文字抖动偏差
369
     *
370
     * @return void
371
     */
372
    public static function captcha($code, $size = [80, 30], $fontSize = 14, $fontPath = 'simkai', $pixelNum = 2, $pixelColor = 5, $padding = 8, $margin = 7, $base = 20, $baseOffset = 4)
373
    {
374
        header("Cache-Control: no-cache, must-revalidate");
375
        header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
376
        header("Pragma: no-cache");
377
        header("Cache-control: private");
378
        header('Content-Type: image/png');
379
        $codeLength = Strings::length($code);
380
        if ($image = imagecreatetruecolor($size[0], $size[1])) {
381
            imagefilledrectangle($image, 0, 0, $size[0] - 1, $size[1] - 1, imagecolorallocate($image, mt_rand(235, 255), mt_rand(235, 255), mt_rand(235, 255)));
382
            for ($i = 0; $i < $pixelColor; $i++) {
383
                $noiseColor = imagecolorallocate($image, mt_rand(150, 225), mt_rand(150, 225), mt_rand(150, 225));
384
                for ($j = 0; $j < $pixelNum; $j++) {
385
                    imagestring($image, 1, mt_rand(-10, $size[0]), mt_rand(-10, $size[1]), Strings::random(1), $noiseColor);
386
                }
387
            }
388
            $codeArray = Strings::split($code);
389
            for ($i = 0; $i < $codeLength; ++$i) {
390
                $color = imagecolorallocate($image, mt_rand(0, 100), mt_rand(20, 120), mt_rand(50, 150));
391
                imagettftext($image, $fontSize, mt_rand(-10, 10), $margin, mt_rand($base - $baseOffset, $base + $baseOffset), $color, $fontPath, $codeArray[$i]);
392
                $margin += (imagefontwidth($fontSize) + $padding);
393
            }
394
            imagepng($image);
395
            imagedestroy($image);
396
        }
397
    }
398
399
    /**
400
     * 释放输入输出图片
401
     */
402
    public function __destruct()
403
    {
404
        $this->destroy();
405
    }
406
}
407