|
@@ -67,14 +67,32 @@ export const getInputFirstPaper = folderPath => {
|
|
|
});
|
|
|
};
|
|
|
|
|
|
-export function saveCropperImage(paperInfo, collectConfig) {
|
|
|
+function saveThumbsImage(imgPath, outputThumbsPath) {
|
|
|
+ const outputThumbsDir = path.dirname(outputThumbsPath);
|
|
|
+ if (!fs.existsSync(outputThumbsDir)) makeDirSync(outputThumbsDir);
|
|
|
+
|
|
|
+ // slice图:完整处理流程
|
|
|
+ let imgObj = gm(imgPath);
|
|
|
+
|
|
|
+ // 生成缩略图
|
|
|
+ imgObj.resize(500).quality(80);
|
|
|
+
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ imgObj.write(outputThumbsPath, function(err) {
|
|
|
+ if (err) {
|
|
|
+ reject(err);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ resolve(outputThumbsPath);
|
|
|
+ });
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+function saveSliceImage(paperInfo, collectConfig) {
|
|
|
const imgPath = paperInfo.filepath;
|
|
|
const outputSlicelPath = paperInfo.imagesPath;
|
|
|
const outputSliceDir = path.dirname(outputSlicelPath);
|
|
|
if (!fs.existsSync(outputSliceDir)) makeDirSync(outputSliceDir);
|
|
|
- const outputThumbsPath = paperInfo.thumbsPath;
|
|
|
- const outputThumbsDir = path.dirname(outputThumbsPath);
|
|
|
- if (!fs.existsSync(outputThumbsDir)) makeDirSync(outputThumbsDir);
|
|
|
|
|
|
const { codeArea, coverArea, tailorTailorArea, imageRotate } = collectConfig;
|
|
|
|
|
@@ -122,22 +140,17 @@ export function saveCropperImage(paperInfo, collectConfig) {
|
|
|
reject(err);
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- // 生成缩略图
|
|
|
- imgObj.resize(500).quality(80);
|
|
|
- imgObj.write(outputThumbsPath, function(err) {
|
|
|
- if (err) {
|
|
|
- reject(err);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- imgObj.resize(500).quality(80);
|
|
|
-
|
|
|
- resolve({
|
|
|
- imagesPath: outputSlicelPath,
|
|
|
- thumbsPath: outputThumbsPath
|
|
|
- });
|
|
|
- });
|
|
|
+ resolve(outputSlicelPath);
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
+export async function saveCropperImage(paperInfo, collectConfig) {
|
|
|
+ const outputSlicelPath = await saveSliceImage(paperInfo, collectConfig);
|
|
|
+ const outputThumbsPath = await saveThumbsImage(
|
|
|
+ outputSlicelPath,
|
|
|
+ paperInfo.thumbsPath
|
|
|
+ );
|
|
|
+
|
|
|
+ return { outputSlicelPath, outputThumbsPath };
|
|
|
+}
|