|
|
@@ -14,37 +14,6 @@ class WorkOrder extends Api
|
|
|
protected $noNeedLogin = ['*'];
|
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
|
- /**
|
|
|
- * 通过店铺ID-查询对应店铺表数据
|
|
|
- *
|
|
|
- */
|
|
|
- public function PatternApi()
|
|
|
- {
|
|
|
- $params = $this->request->param('pattern_id', '');
|
|
|
- $tableName = 'pattern-' . $params;
|
|
|
-
|
|
|
- // 连接 MongoDB
|
|
|
- $mongo = Db::connect('mongodb');
|
|
|
-
|
|
|
- // 查询指定 skc 的数据
|
|
|
- $data = $mongo->table($tableName)
|
|
|
- ->field('
|
|
|
- name,
|
|
|
- skc,
|
|
|
- file
|
|
|
- ')
|
|
|
- ->where("skc", '0853004152036')
|
|
|
- ->select();
|
|
|
-
|
|
|
- $data = json_decode(json_encode($data), true); // 数组
|
|
|
-
|
|
|
- return json([
|
|
|
- 'code' => 0,
|
|
|
- 'msg' => '获取成功',
|
|
|
- 'data' => $data
|
|
|
- ]);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 出图接口
|
|
|
* 此方法处理图像转换为文本的请求,将图像信息存入队列以供后续处理。
|
|
|
@@ -64,46 +33,40 @@ class WorkOrder extends Api
|
|
|
*/
|
|
|
public function imgtowimg()
|
|
|
{
|
|
|
- $prompt = $this->request->param('prompt', '');
|
|
|
- $denoising = (float)$this->request->param('denoising_strength', 0.2);
|
|
|
- $scale = (float)$this->request->param('scale', 2.0);
|
|
|
- $modelName = $this->request->param('model', 'realisticVisionV51_v51VAE-inpainting.safetensors [f0d4872d24]');
|
|
|
-
|
|
|
- // 原图路径
|
|
|
- $imgRelPath = 'uploads/operate/ai/Preview/arr/0828004096727.png';
|
|
|
+ //原图路径
|
|
|
+ $imgRelPath = 'uploads/operate/ai/Preview/arr/该图案传递了旅行和无忧无虑的心情采用明快的色调充满活力的复古.png';
|
|
|
$imgPath = ROOT_PATH . 'public/' . $imgRelPath;
|
|
|
|
|
|
if (!file_exists($imgPath)) {
|
|
|
return json(['code' => 1, 'msg' => '原图不存在:' . $imgRelPath]);
|
|
|
}
|
|
|
|
|
|
- // 获取原图尺寸 × 倍数
|
|
|
- list($originW, $originH) = getimagesize($imgPath);
|
|
|
- $targetW = intval($originW * $scale);
|
|
|
- $targetH = intval($originH * $scale);
|
|
|
-
|
|
|
- // base64 编码
|
|
|
+ // 原图 base64 编码
|
|
|
$imgData = file_get_contents($imgPath);
|
|
|
$base64Img = base64_encode($imgData);
|
|
|
$initImage = 'data:image/png;base64,' . $base64Img;
|
|
|
|
|
|
- // 请求体
|
|
|
+ // 参数设置
|
|
|
$postData = json_encode([
|
|
|
- 'prompt' => $prompt,
|
|
|
- 'steps' => 30,
|
|
|
+ 'prompt' => '',
|
|
|
+ 'sampler_name' => 'DPM++ 2M SDE Heun',
|
|
|
+ 'seed' => -1,
|
|
|
+ 'steps' => 20,
|
|
|
'cfg_scale' => 7,
|
|
|
- 'denoising_strength' => $denoising,
|
|
|
- 'width' => $targetW,
|
|
|
- 'height' => $targetH,
|
|
|
- 'resize_mode' => 1,
|
|
|
- 'inpaint_full_res' => true,
|
|
|
+ 'denoising_strength' => 0.2,
|
|
|
+ 'width' => 1024,
|
|
|
+ 'height' => 2048,
|
|
|
'inpainting_fill' => 1,
|
|
|
+ 'resize_mode' => 0, // 自动等比缩放+填充
|
|
|
+ 'inpaint_full_res' => true,
|
|
|
'init_images' => [$initImage],
|
|
|
'override_settings' => [
|
|
|
- 'sd_model_checkpoint' => $modelName
|
|
|
+ 'sd_model_checkpoint' => 'realisticVisionV51_v51VAE-inpainting.safetensors [f0d4872d24]',
|
|
|
+ 'sd_vae' => 'anything-v4.5.vae.pt' // 设置外挂 VAE 模型
|
|
|
]
|
|
|
]);
|
|
|
|
|
|
+ //调用接口
|
|
|
$apiUrl = "http://20.0.17.233:45001/sdapi/v1/img2img";
|
|
|
$headers = ['Content-Type: application/json'];
|
|
|
|
|
|
@@ -124,10 +87,10 @@ class WorkOrder extends Api
|
|
|
|
|
|
$data = json_decode($response, true);
|
|
|
if (!isset($data['images'][0])) {
|
|
|
- return json(['code' => 1, 'msg' => '接口未返回图像数据']);
|
|
|
+ return json(['code' => 1, 'msg' => '未返回图像数据']);
|
|
|
}
|
|
|
|
|
|
- // 保存图像:原图名 + -1
|
|
|
+ // 保存结果图像
|
|
|
$resultImg = base64_decode($data['images'][0]);
|
|
|
$saveDir = ROOT_PATH . 'public/uploads/img2img/';
|
|
|
if (!is_dir($saveDir)) {
|
|
|
@@ -135,19 +98,105 @@ class WorkOrder extends Api
|
|
|
}
|
|
|
|
|
|
$originalBaseName = pathinfo($imgRelPath, PATHINFO_FILENAME);
|
|
|
- $fileName = $originalBaseName . '-1.png';
|
|
|
+ $fileName = $originalBaseName . '.png';
|
|
|
$savePath = $saveDir . $fileName;
|
|
|
file_put_contents($savePath, $resultImg);
|
|
|
|
|
|
return json([
|
|
|
'code' => 0,
|
|
|
- 'msg' => '图像生成成功',
|
|
|
+ 'msg' => '图像上下扩展生成成功',
|
|
|
'data' => [
|
|
|
'origin_url' => '/uploads/img2img/' . $fileName
|
|
|
]
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+// public function imgtowimg()
|
|
|
+// {
|
|
|
+// $prompt = $this->request->param('prompt', '');
|
|
|
+// $denoising = (float)$this->request->param('denoising_strength', 0.2);
|
|
|
+// $scale = (float)$this->request->param('scale', 2.0);
|
|
|
+// $modelName = $this->request->param('model', 'realisticVisionV51_v51VAE-inpainting.safetensors [f0d4872d24]');
|
|
|
+//
|
|
|
+// // 原图路径
|
|
|
+// $imgRelPath = 'uploads/operate/ai/Preview/arr/0828004096727.png';
|
|
|
+// $imgPath = ROOT_PATH . 'public/' . $imgRelPath;
|
|
|
+//
|
|
|
+// if (!file_exists($imgPath)) {
|
|
|
+// return json(['code' => 1, 'msg' => '原图不存在:' . $imgRelPath]);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 获取原图尺寸 × 倍数
|
|
|
+// list($originW, $originH) = getimagesize($imgPath);
|
|
|
+// $targetW = intval($originW * $scale);
|
|
|
+// $targetH = intval($originH * $scale);
|
|
|
+//
|
|
|
+// // base64 编码
|
|
|
+// $imgData = file_get_contents($imgPath);
|
|
|
+// $base64Img = base64_encode($imgData);
|
|
|
+// $initImage = 'data:image/png;base64,' . $base64Img;
|
|
|
+//
|
|
|
+// // 请求体
|
|
|
+// $postData = json_encode([
|
|
|
+// 'prompt' => $prompt,
|
|
|
+// 'steps' => 30,
|
|
|
+// 'cfg_scale' => 7,
|
|
|
+// 'denoising_strength' => $denoising,
|
|
|
+// 'width' => $targetW,
|
|
|
+// 'height' => $targetH,
|
|
|
+// 'resize_mode' => 1,
|
|
|
+// 'inpaint_full_res' => true,
|
|
|
+// 'inpainting_fill' => 1,
|
|
|
+// 'init_images' => [$initImage],
|
|
|
+// 'override_settings' => [
|
|
|
+// 'sd_model_checkpoint' => $modelName
|
|
|
+// ]
|
|
|
+// ]);
|
|
|
+//
|
|
|
+// $apiUrl = "http://20.0.17.233:45001/sdapi/v1/img2img";
|
|
|
+// $headers = ['Content-Type: application/json'];
|
|
|
+//
|
|
|
+// $ch = curl_init();
|
|
|
+// curl_setopt($ch, CURLOPT_URL, $apiUrl);
|
|
|
+// curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
+// curl_setopt($ch, CURLOPT_POST, true);
|
|
|
+// curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
+// curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
|
|
|
+// curl_setopt($ch, CURLOPT_TIMEOUT, 90);
|
|
|
+// $response = curl_exec($ch);
|
|
|
+// $error = curl_error($ch);
|
|
|
+// curl_close($ch);
|
|
|
+//
|
|
|
+// if ($error) {
|
|
|
+// return json(['code' => 1, 'msg' => '请求失败:' . $error]);
|
|
|
+// }
|
|
|
+//
|
|
|
+// $data = json_decode($response, true);
|
|
|
+// if (!isset($data['images'][0])) {
|
|
|
+// return json(['code' => 1, 'msg' => '接口未返回图像数据']);
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 保存图像:原图名 + -1
|
|
|
+// $resultImg = base64_decode($data['images'][0]);
|
|
|
+// $saveDir = ROOT_PATH . 'public/uploads/img2img/';
|
|
|
+// if (!is_dir($saveDir)) {
|
|
|
+// mkdir($saveDir, 0755, true);
|
|
|
+// }
|
|
|
+//
|
|
|
+// $originalBaseName = pathinfo($imgRelPath, PATHINFO_FILENAME);
|
|
|
+// $fileName = $originalBaseName . '-1.png';
|
|
|
+// $savePath = $saveDir . $fileName;
|
|
|
+// file_put_contents($savePath, $resultImg);
|
|
|
+//
|
|
|
+// return json([
|
|
|
+// 'code' => 0,
|
|
|
+// 'msg' => '图像生成成功',
|
|
|
+// 'data' => [
|
|
|
+// 'origin_url' => '/uploads/img2img/' . $fileName
|
|
|
+// ]
|
|
|
+// ]);
|
|
|
+// }
|
|
|
+
|
|
|
/**
|
|
|
* 后期图像处理
|
|
|
* /sdapi/v1/extra-single-image
|
|
|
@@ -435,6 +484,35 @@ class WorkOrder extends Api
|
|
|
// ]);
|
|
|
// }
|
|
|
// }
|
|
|
+ /**
|
|
|
+ * 通过店铺ID-查询对应店铺表数据
|
|
|
+ *
|
|
|
+ */
|
|
|
+ public function PatternApi()
|
|
|
+ {
|
|
|
+ $params = $this->request->param('pattern_id', '');
|
|
|
+ $tableName = 'pattern-' . $params;
|
|
|
+
|
|
|
+ // 连接 MongoDB
|
|
|
+ $mongo = Db::connect('mongodb');
|
|
|
|
|
|
+ // 查询指定 skc 的数据
|
|
|
+ $data = $mongo->table($tableName)
|
|
|
+ ->field('
|
|
|
+ name,
|
|
|
+ skc,
|
|
|
+ file
|
|
|
+ ')
|
|
|
+ ->where("skc", '0853004152036')
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $data = json_decode(json_encode($data), true); // 数组
|
|
|
+
|
|
|
+ return json([
|
|
|
+ 'code' => 0,
|
|
|
+ 'msg' => '获取成功',
|
|
|
+ 'data' => $data
|
|
|
+ ]);
|
|
|
+ }
|
|
|
|
|
|
}
|