Commit a597bf9f by 蒋勇

surport png2jpg

parent c87b2c9b
...@@ -2,6 +2,7 @@ const system = require("../../system") ...@@ -2,6 +2,7 @@ const system = require("../../system")
const uuidv4 = require('uuid/v4'); const uuidv4 = require('uuid/v4');
const ApiBase = require("../api.base"); const ApiBase = require("../api.base");
const fs = require("fs"); const fs = require("fs");
import { rename } from 'fs/promises';
const mime = require("mime"); const mime = require("mime");
const gm = require("gm"); const gm = require("gm");
const imageMagick = gm.subClass({ imageMagick: true }); const imageMagick = gm.subClass({ imageMagick: true });
...@@ -61,6 +62,43 @@ class ImageHandleApi extends ApiBase { ...@@ -61,6 +62,43 @@ class ImageHandleApi extends ApiBase {
fs.unlink(tmpfile, function (err) { }); fs.unlink(tmpfile, function (err) { });
return system.getResult2({ "url": rtn.url }, null); return system.getResult2({ "url": rtn.url }, null);
} }
//判断是否是png
async isPng (srcImg) {
let p = new Promise((res, rej) => {
im.identify(srcImg, function (err, metadata) {
if (err) {
console.log(err)
rej(err)
} else {
console.log(JSON.stringify(metadata.format));
if (metadata.format == "PNG") {
res(true);
} else {
res(false);
}
}
})
})
return p;
}
async function png2jpg (srcPng, dstJpg) {
let p = new Promise((res, rej) => {
child_process.exec(`convert ${srcPng} ${dstJpg}`, function (err, std, ste) {
if (err) {
console.log(err)
rej(err)
} else {
res(std)
}
})
})
return p
}
//商标营业执照处理,大小小于2M,宽高10-50cm //商标营业执照处理,大小小于2M,宽高10-50cm
//身份证同营业执照处理(调整上传至oss的执照文件,通过文件名称下载至本地调整) //身份证同营业执照处理(调整上传至oss的执照文件,通过文件名称下载至本地调整)
async bzLicenseForTM(obj) { async bzLicenseForTM(obj) {
...@@ -77,7 +115,21 @@ class ImageHandleApi extends ApiBase { ...@@ -77,7 +115,21 @@ class ImageHandleApi extends ApiBase {
var epspath = "/tmp/" + basename + ".eps"; var epspath = "/tmp/" + basename + ".eps";
var pdfpathKey = basename + ".pdf"; var pdfpathKey = basename + ".pdf";
var pdfpath = "/tmp/" + basename + ".pdf"; var pdfpath = "/tmp/" + basename + ".pdf";
var result = await this.ossClient.downfile(jpgpath); var result = await this.ossClient.downfile(jpgpath);
//检查是否是png
if (this.isPng(jpgpathtmp)){
let pngPath = "/tmp/" + basename + ".png"
//修改jpgpathtmp文件名为*.png
await rename(jpgpathtmp, pngPath)
//转换
await png2jpg(pngPath, jpgpathtmp)
fs.unlink(pngPath, function (err) { });
}
//转换为eps //转换为eps
var cmd2eps = "jpeg2ps -p " + " a4 " + jpgpathtmp + " -o " + epspath; var cmd2eps = "jpeg2ps -p " + " a4 " + jpgpathtmp + " -o " + epspath;
var x = await this.execClient.exec(cmd2eps); var x = await this.execClient.exec(cmd2eps);
...@@ -89,6 +141,7 @@ class ImageHandleApi extends ApiBase { ...@@ -89,6 +141,7 @@ class ImageHandleApi extends ApiBase {
fs.unlink(jpgpathtmp, function (err) { }); fs.unlink(jpgpathtmp, function (err) { });
fs.unlink(epspath, function (err) { }); fs.unlink(epspath, function (err) { });
fs.unlink(pdfpath, function (err) { }); fs.unlink(pdfpath, function (err) { });
return system.getResult2({ "url": rtn.url }, null); return system.getResult2({ "url": rtn.url }, null);
} }
//商标营业执照处理,大小小于2M,宽高10-50cm //商标营业执照处理,大小小于2M,宽高10-50cm
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment