20201112
This commit is contained in:
62
application/api/job/img.php
Normal file
62
application/api/job/img.php
Normal file
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
namespace app\api\job;
|
||||
|
||||
use think\queue\Job;
|
||||
|
||||
class img {
|
||||
|
||||
//put your code here
|
||||
|
||||
public function fire(Job $job, $data) {
|
||||
// $this->tttt($data['name']);
|
||||
$this->imgCL($data['name'], $data['course']);
|
||||
$job->delete();
|
||||
}
|
||||
|
||||
// public function tttt($name) {
|
||||
// file_put_contents('d:/1.txt',$name.'--' , FILE_APPEND);
|
||||
// }
|
||||
|
||||
/**
|
||||
* 处理图片主方法
|
||||
*/
|
||||
public function imgCL($name, $course) {
|
||||
$max = $this->getmax($course);
|
||||
$lim = [];
|
||||
if (preg_match("/^[\x7f-\xff]+$/", $name) && strlen($name) == 9) {
|
||||
$lim = [640, 890];
|
||||
} else if (preg_match("/^[\x7f-\xff]+$/", $name) && strlen($name) == 6) {
|
||||
$lim = [670, 890];
|
||||
} else {
|
||||
$left = (730 - ((35 * strlen($name)) / 2));
|
||||
$lim = [$left, 890];
|
||||
}
|
||||
$template = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'template.png';
|
||||
$ziti = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'siyuan.ttf';
|
||||
$image = \think\Image::open($template);
|
||||
$image->text($name, $ziti, 50, '#000000', $lim)
|
||||
->text('NO.ZYMR' . (20210619001 + $max), $ziti, 25, '#000000', [573, 650])
|
||||
->save(ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img' . DS . $course . DS . (1 + $max) . '_' . $name . '.png');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前证书流水号最大值
|
||||
*/
|
||||
private function getmax($course) {
|
||||
$dir = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'img/' . $course . DS;
|
||||
$res = scandir($dir);
|
||||
$big = 0;
|
||||
foreach ($res as $v) {
|
||||
if ($v == '.' || $v == '..') {
|
||||
continue;
|
||||
}
|
||||
$cac = intval(substr($v, 0, stripos($v, '_')));
|
||||
if ($cac > $big) {
|
||||
$big = $cac;
|
||||
}
|
||||
}
|
||||
return $big;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user