gioi han so mau cho 1 doi tuong

This commit is contained in:
2020-12-22 16:17:34 +07:00
parent 40df99acd9
commit fc0f2ccc0f
5 changed files with 51 additions and 30 deletions

View File

@@ -108,6 +108,8 @@ class ListManagementController extends Controller {
$url = CaptureLogs::findOne($data['id'])->image;
if ($listManagement) {
$images = json_decode($listManagement->image, true);
if (count($images) >= \Yii::$app->params['maxPicture'])
return ["status" => false, "text" => "Mỗi đối tượng chỉ nhận tối đa " . \Yii::$app->params['maxPicture'] . " hình ảnh mẫu"];
$add = true;
foreach ($images as $key => $value) {
if ($value['url'] === $url)
@@ -135,6 +137,7 @@ class ListManagementController extends Controller {
file_get_contents("http://localhost:2305/update-feature");
return ["status" => true];
}
return ["status" => false, "text" => "Hình ảnh này đã được chọn làm mẫu cho đối tượng này!"];
} else {
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
@@ -169,7 +172,8 @@ class ListManagementController extends Controller {
"birthday" => date("d/m/Y", $ListManagement->birthday),
"telephone" => $ListManagement->telephone,
"address" => $ListManagement->address,
"image" => count($images) > 0 ? "/data/uploads/face/" . $images[0]['url'] : "/images/user2-160x160.jpg"
"image" => count($images) > 0 ? "/data/uploads/face/" . $images[0]['url'] : "/images/user2-160x160.jpg",
"canUpload" => count($images) >= Yii::$app->params['maxPicture'] ? false : true
];
}
}
@@ -372,21 +376,23 @@ class ListManagementController extends Controller {
$targetPath = $RootFolder . "/face";
FileHelper::createDirectory($targetPath, 0777);
foreach ($data['images'] as $key => $value) {
$key = common::generateRandomString();
$fileName = "face_" . $key . "_" . time() . ".png";
$img = file_get_contents($value);
if ($img !== "null") {
file_put_contents($targetPath . "/" . $fileName, $img);
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
$ft[] = [
"url" => $fileName,
"features" => $features['results'][0]['feature'],
"features512" => isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : []
];
if ($key < Yii::$app->params['maxPicture']) {
$key = common::generateRandomString();
$fileName = "face_" . $key . "_" . time() . ".png";
$img = file_get_contents($value);
if ($img !== "null") {
file_put_contents($targetPath . "/" . $fileName, $img);
$features = json_decode(common::requestToEngine("/get-feature", [
"image_paths" => [
["url" => "/var/www/html/BiFace_Server_Lite/web/data/uploads/face/" . $fileName, "type" => "raw"]
]
]), true);
$ft[] = [
"url" => $fileName,
"features" => $features['results'][0]['feature'],
"features512" => isset($features['results'][0]['feature512']) ? $features['results'][0]['feature512'] : []
];
}
}
}
$model = ListManagement::findOne(['code' => $data['idStaff']]);
@@ -427,13 +433,19 @@ class ListManagementController extends Controller {
foreach ($results as $key => $value) {
$images = [];
foreach ($value['images'] as $k => $v) {
$key = common::generateRandomString();
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face";
$fileName = "face_" . $key . "_" . time() . ".png";
FileHelper::createDirectory($targetPath, 0777);
file_put_contents($targetPath . "/" . $fileName, base64_decode($v['url']));
$images[] = ["url" => $fileName, "features" => $v['features']];
if ($k < Yii::$app->params['maxPicture']) {
$key = common::generateRandomString();
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
$targetPath = $RootFolder . "/face";
$fileName = "face_" . $key . "_" . time() . ".png";
FileHelper::createDirectory($targetPath, 0777);
file_put_contents($targetPath . "/" . $fileName, base64_decode($v['url']));
$images[] = [
"url" => $fileName,
"features" => $v['features'],
"features512" => isset($v['features512']) ? $v['features512'] : []
];
}
}
$model = ListManagement::findOne(['code' => $value['code']]);
if ($model) {