luoyutianyang commited on
Commit
ce35450
·
verified ·
1 Parent(s): 1fb1e33

Update egg-api.js

Browse files
Files changed (1) hide show
  1. egg-api.js +10 -9
egg-api.js CHANGED
@@ -70,11 +70,6 @@ async function videoToGif(inputVideoPath, outputGifPath) {
70
  .run();
71
  });
72
  }
73
- // 下载并转换图片到内存的辅助函数
74
- async function downloadAndConvertImage(url) {
75
- const response = await axios.get(url, { responseType: 'arraybuffer' });
76
- return await Jimp.read(response.data);
77
- }
78
 
79
  // 处理图片的 Express 接口
80
  app.get('/process-image', async (req, res) => {
@@ -117,7 +112,7 @@ app.get('/process-image', async (req, res) => {
117
  writer.on('error', reject);
118
  });
119
 
120
- replacementImageBuffer = await Jimp.read(tempImagePath)
121
  }
122
  console.log('图片下载完成:', tempImagePath);
123
 
@@ -158,6 +153,7 @@ app.get('/process-image', async (req, res) => {
158
  }
159
  } else {
160
  console.error('未检测到人脸或faces数组为空');
 
161
  }
162
 
163
  // 保存处理后的图片
@@ -173,7 +169,9 @@ app.get('/process-image', async (req, res) => {
173
  } else {
174
  // 删除临时文件
175
  fs.unlinkSync(tempImagePath);
176
- fs.unlinkSync(tempImagePaths);
 
 
177
  fs.unlinkSync(outputImagePath);
178
  }
179
  });
@@ -223,7 +221,7 @@ app.get('/processGif', async (req, res) => {
223
  writer.on('finish', resolve);
224
  writer.on('error', reject);
225
  });
226
- replacementImageBuffer=await Jimp.read(tempGifPaths)
227
  }
228
  console.log('GIF下载完成:', tempGifPath);
229
 
@@ -274,6 +272,7 @@ app.get('/processGif', async (req, res) => {
274
  }
275
  } else {
276
  console.error('未检测到人脸或faces数组为空');
 
277
  }
278
 
279
  videoWriter.write(frame);
@@ -294,7 +293,9 @@ app.get('/processGif', async (req, res) => {
294
  } else {
295
  // 删除临时文件
296
  fs.unlinkSync(tempGifPath);
297
- fs.unlinkSync(tempGifPaths);
 
 
298
  fs.unlinkSync(tempVideoPath);
299
  fs.unlinkSync(outputGifPath);
300
  }
 
70
  .run();
71
  });
72
  }
 
 
 
 
 
73
 
74
  // 处理图片的 Express 接口
75
  app.get('/process-image', async (req, res) => {
 
112
  writer.on('error', reject);
113
  });
114
 
115
+ replacementImageBuffer = await Jimp.read(tempImagePaths)
116
  }
117
  console.log('图片下载完成:', tempImagePath);
118
 
 
153
  }
154
  } else {
155
  console.error('未检测到人脸或faces数组为空');
156
+ throw new Error('No faces detected in the image.');
157
  }
158
 
159
  // 保存处理后的图片
 
169
  } else {
170
  // 删除临时文件
171
  fs.unlinkSync(tempImagePath);
172
+ if (fs.existsSync(tempImagePaths)) {
173
+ fs.unlinkSync(tempImagePaths);
174
+ }
175
  fs.unlinkSync(outputImagePath);
176
  }
177
  });
 
221
  writer.on('finish', resolve);
222
  writer.on('error', reject);
223
  });
224
+ replacementImageBuffer = await Jimp.read(tempGifPaths)
225
  }
226
  console.log('GIF下载完成:', tempGifPath);
227
 
 
272
  }
273
  } else {
274
  console.error('未检测到人脸或faces数组为空');
275
+ throw new Error('No faces detected in the image.');
276
  }
277
 
278
  videoWriter.write(frame);
 
293
  } else {
294
  // 删除临时文件
295
  fs.unlinkSync(tempGifPath);
296
+ if (fs.existsSync(tempGifPaths)) {
297
+ fs.unlinkSync(tempGifPaths);
298
+ }
299
  fs.unlinkSync(tempVideoPath);
300
  fs.unlinkSync(outputGifPath);
301
  }