89 lines
2.9 KiB
PHP
89 lines
2.9 KiB
PHP
<?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']);
|
|
if ($data['course'] == 'ZYMR') {
|
|
$this->imgCL($data['name'], $data['course']);
|
|
} else {
|
|
$this->imgZL($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');
|
|
}
|
|
|
|
/**
|
|
* 处理图片主方法
|
|
*/
|
|
public function imgZL($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 . 'template1.png';
|
|
$ziti = ROOT_PATH . 'public' . DS . 'zhengshu' . DS . 'siyuan.ttf';
|
|
$image = \think\Image::open($template);
|
|
$image->text($name, $ziti, 50, '#000000', $lim)
|
|
->text('NO.ZLLJ' . (20210807001 + $max), $ziti, 30, '#000000', [573, 660])
|
|
->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;
|
|
}
|
|
|
|
}
|