|
@@ -75,15 +75,15 @@
|
|
|
<div style="padding: 10px 15px; overflow: auto; height: calc(100% - 37px);">
|
|
|
<div class="handle-item">
|
|
|
<label class="handle-label">选择算法:</label>
|
|
|
- <el-select size="small" v-model="handleData.type" style="width: 100px;">
|
|
|
- <el-option value="1" label="高性能"></el-option>
|
|
|
- <el-option value="2" label="神经网络"></el-option>
|
|
|
- </el-select> 算法
|
|
|
+ <el-select size="small" v-model="handleData.type" style="width: 150px;">
|
|
|
+ <el-option value="1" label="深度算法"></el-option>
|
|
|
+ <el-option value="2" label="高性能算法"></el-option>
|
|
|
+ </el-select>
|
|
|
</div>
|
|
|
|
|
|
<div class="handle-item">
|
|
|
<label class="handle-label">降噪程度:</label>
|
|
|
- <el-select size="small" v-model="handleData.noise" style="width: 100px;">
|
|
|
+ <el-select size="small" v-model="handleData.noise" style="width: 150px;">
|
|
|
<el-option :value="-1" label="不降噪"></el-option>
|
|
|
<el-option :value="0" label="低"></el-option>
|
|
|
<el-option :value="1" label="中"></el-option>
|
|
@@ -94,15 +94,18 @@
|
|
|
|
|
|
<div class="handle-item">
|
|
|
<label class="handle-label">放大倍数:</label>
|
|
|
- <el-select v-if="handleData.type == 2" size="small" v-model="handleData.upscale" style="width: 100px;" >
|
|
|
+ <el-select v-if="handleData.type == 2" size="small" v-model="handleData.upscale" style="width: 150px;" >
|
|
|
<el-option :value="1" label="1"></el-option>
|
|
|
<el-option :value="2" label="2"></el-option>
|
|
|
<el-option :value="4" label="4"></el-option>
|
|
|
<el-option :value="8" label="8"></el-option>
|
|
|
</el-select>
|
|
|
- <el-input-number v-else size="mini" v-model="handleData.upscale" :min="1" :max="6" :step="0.5" style="width: 100px;"></el-input-number>
|
|
|
+ <el-input-number v-else size="mini" v-model="handleData.upscale" :min="1" :max="6" :step="0.5" style="width: 150px;"></el-input-number>
|
|
|
+ 倍
|
|
|
</div>
|
|
|
|
|
|
+ <div v-if="handleData.type == '1'" style="text-align: center; color: #F22C40;margin-top: 20px;">深度算法只适应于win10及以上系统</div>
|
|
|
+
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -408,6 +411,13 @@ export default {
|
|
|
|
|
|
this.completeNum = 0;
|
|
|
this.failNum = 0;
|
|
|
+ this.mergeLoading = this.$loading({
|
|
|
+ lock: true,
|
|
|
+ text: '图片处理中,请稍后...',
|
|
|
+ spinner: 'el-icon-loading',
|
|
|
+ background: 'rgba(0, 0, 0, 0.7)'
|
|
|
+ });
|
|
|
+
|
|
|
if(this.handleData.type == '2'){ // 算法1 神经网络
|
|
|
this.execWaifu();
|
|
|
} else {
|
|
@@ -434,7 +444,7 @@ export default {
|
|
|
|
|
|
let lastIndex2 = item.name.lastIndexOf('.');
|
|
|
let newName = item.name.slice(0, lastIndex2) + '.' + suffix;
|
|
|
- newPath = this.handleData.newPath + "\/" + newName;
|
|
|
+ newPath = this.handleData.newPath + separator + newName;
|
|
|
openPath = newPath;
|
|
|
|
|
|
if(item.interval){
|
|
@@ -473,27 +483,27 @@ export default {
|
|
|
'-m',
|
|
|
modelDir
|
|
|
];
|
|
|
-
|
|
|
+
|
|
|
await electronApi.spawnExec(params2).then(result => {
|
|
|
this.addWatermark(index, this.imgList[index], tempPath, newPath).then(res => {
|
|
|
this.completeNum ++;
|
|
|
item.percent = 100;
|
|
|
this.imgList.splice(index, 1, item);
|
|
|
clearInterval(item.interval);
|
|
|
- console.log('---添加水印成功---', res)
|
|
|
+ fs.unlinkSync(tempPath);
|
|
|
}).catch(err => {
|
|
|
this.failNum ++;
|
|
|
clearInterval(item.interval);
|
|
|
- console.log('---添加水印失败---', err)
|
|
|
+ fs.unlinkSync(tempPath);
|
|
|
});
|
|
|
}).catch(err => {
|
|
|
this.failNum ++;
|
|
|
clearInterval(item.interval);
|
|
|
- console.log('---------无损放大失败-------', err.stderr.toString());
|
|
|
});
|
|
|
}
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
+ this.mergeLoading.close();
|
|
|
let tips = '导出成功';
|
|
|
if(this.failNum > 0){
|
|
|
tips = '导出成功,失败 '+this.failNum+' 个';
|
|
@@ -523,16 +533,18 @@ export default {
|
|
|
let newPath = item.path;
|
|
|
let suffix = item.type;
|
|
|
let tempPath = path.resolve(os.tmpdir(), generate(50) + ".png"); //newPath; // 缓存路径
|
|
|
-
|
|
|
- if(this.handleData.pathType == '2'){ // 判断有无 “优速无损放大器” 文件夹
|
|
|
- let lastIndex = item.name.lastIndexOf('.');
|
|
|
- let newName = item.name.slice(0, lastIndex) + '.' + suffix;
|
|
|
- newPath = this.handleData.newPath + "\/" + newName;
|
|
|
- }else{
|
|
|
- newPath = item.path.slice(0, lastIndex) + '.' + suffix;
|
|
|
+
|
|
|
+ if(fs.existsSync(this.downloadDir + separator + pjson.softInfo.softName)){
|
|
|
+ this.handleData.newPath = this.downloadDir + separator + pjson.softInfo.softName;
|
|
|
+ } else {
|
|
|
+ fs.mkdirSync(this.downloadDir + separator + pjson.softInfo.softName);
|
|
|
+ this.handleData.newPath = this.downloadDir + separator + pjson.softInfo.softName;
|
|
|
}
|
|
|
+
|
|
|
+ let lastIndex2 = item.name.lastIndexOf('.');
|
|
|
+ let newName = item.name.slice(0, lastIndex2) + '.' + suffix;
|
|
|
+ newPath = this.handleData.newPath + separator + newName;
|
|
|
openPath = newPath;
|
|
|
-
|
|
|
if(item.interval){
|
|
|
clearInterval(item.interval);
|
|
|
}
|
|
@@ -589,10 +601,12 @@ export default {
|
|
|
item.percent = 100;
|
|
|
this.imgList.splice(index, 1, item);
|
|
|
clearInterval(item.interval);
|
|
|
+ fs.unlinkSync(tempPath);
|
|
|
console.log('---添加水印成功---', res)
|
|
|
}).catch(err => {
|
|
|
this.failNum ++;
|
|
|
clearInterval(item.interval);
|
|
|
+ fs.unlinkSync(tempPath);
|
|
|
console.log('---添加水印失败---', err)
|
|
|
});
|
|
|
}).catch(err => {
|
|
@@ -603,6 +617,7 @@ export default {
|
|
|
}
|
|
|
|
|
|
setTimeout(()=>{
|
|
|
+ this.mergeLoading.close();
|
|
|
let tips = '导出成功';
|
|
|
if(this.failNum > 0){
|
|
|
tips = '导出成功,失败 '+this.failNum+' 个';
|
|
@@ -689,275 +704,11 @@ export default {
|
|
|
electronApi.call('showItemInfolder',[newPath])
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
- // 文字水印
|
|
|
- async textWatermark(index, imgInfo, newPath, isPreview=false) {
|
|
|
- let m = this.handleData.watermarkDensityX <= 0 ? 3 : this.handleData.watermarkDensityX;
|
|
|
- let n = this.handleData.watermarkDensityY <= 0 ? 3 : this.handleData.watermarkDensityY;
|
|
|
-
|
|
|
- return new Promise((resolve,reject) => {
|
|
|
- let tmpPath = os.tmpdir()+separator+'water_font_'+index+'.png';
|
|
|
- let params = [
|
|
|
- 'convert.exe',
|
|
|
- '-monitor',
|
|
|
- '-background',
|
|
|
- 'none',
|
|
|
- '-fill',
|
|
|
- this.handleData.watermarkColor,
|
|
|
- '-font',
|
|
|
- this.handleData.fonts.toString(),
|
|
|
- '-pointsize',
|
|
|
- this.handleData.watermarkFont,
|
|
|
- '-alpha', 'set', '-channel', 'A', '-evaluate', 'Multiply', this.handleData.watermarkImgOpactiy/100, '+channel', // 透明度
|
|
|
- '-rotate',
|
|
|
- this.handleData.rotate ? this.handleData.rotate : 0,
|
|
|
- 'label:' + (this.handleData.watermarkValue ? this.handleData.watermarkValue : pjson.softInfo.softName),
|
|
|
- '-gravity',
|
|
|
- 'center',
|
|
|
- '-extent',
|
|
|
- this.handleData.watermarkStyle == 2 ? (imgInfo.width/m)+'x'+(imgInfo.height/n) : '100%',
|
|
|
- tmpPath
|
|
|
- ];
|
|
|
-
|
|
|
- electronApi.spawnExec(params,{stderr:(data) => { if(this.menuIndex == '1') { imgInfo.percent = 30;this.imgList.splice(index,1,imgInfo);}}}).then(async (res) => {
|
|
|
- // 生成平铺水印图片
|
|
|
- if(this.handleData.watermarkStyle == 2){ // 平铺
|
|
|
- let tmpPath2 = os.tmpdir()+separator+'water_pu_'+index+'.png';
|
|
|
- let params2 = [
|
|
|
- 'convert.exe',
|
|
|
- '-monitor',
|
|
|
- tmpPath,
|
|
|
- '-write',
|
|
|
- 'mpr:tiler',
|
|
|
- '+delete',
|
|
|
- '-size',
|
|
|
- imgInfo.width+'x'+imgInfo.height,
|
|
|
- 'tile:mpr:tiler',
|
|
|
- tmpPath2
|
|
|
- ];
|
|
|
- await electronApi.spawnExec(params2,{stderr:(data) => { if(this.menuIndex == '1') { imgInfo.percent=60;this.imgList.splice(index,1,imgInfo);}}}).then(async (res2) => {
|
|
|
- await this.waterComposite(index, imgInfo, newPath, tmpPath2, isPreview);
|
|
|
- })
|
|
|
- }else{
|
|
|
- await this.waterComposite(index, imgInfo, newPath, tmpPath, isPreview);
|
|
|
- }
|
|
|
-
|
|
|
- resolve({type:this.menuIndex, index:index, info:imgInfo});
|
|
|
- }).catch(err => {
|
|
|
- reject({type:this.menuIndex, index:index, err: err});
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
- // 图片水印
|
|
|
- async imgWatermark(index, imgInfo, newPath,isPreview=false) {
|
|
|
- let m = this.handleData.watermarkDensityX <= 0 ? 3 : this.handleData.watermarkDensityX;
|
|
|
- let n = this.handleData.watermarkDensityY <= 0 ? 3 : this.handleData.watermarkDensityY;
|
|
|
-
|
|
|
- return new Promise((resolve,reject) => {
|
|
|
- let tmpPath = os.tmpdir()+separator+'water_img_'+index+'.png';
|
|
|
-
|
|
|
- let params = [
|
|
|
- 'convert.exe',
|
|
|
- '-monitor',
|
|
|
- '-background',
|
|
|
- 'none',
|
|
|
- '-resize',
|
|
|
- `${Number(this.handleData.scaling)}%`,
|
|
|
- '-alpha', 'set', '-channel', 'A', '-evaluate', 'Multiply', this.handleData.watermarkImgOpactiy/100, '+channel', // 透明度
|
|
|
- '-rotate',
|
|
|
- this.handleData.rotate ? this.handleData.rotate : 0,
|
|
|
- '-gravity',
|
|
|
- 'center',
|
|
|
- '-extent',
|
|
|
- this.handleData.watermarkStyle == 2 ? (imgInfo.width/m)+'x'+(imgInfo.height/n) : '100%',
|
|
|
- this.handleData.watermarkImgPath,
|
|
|
- tmpPath
|
|
|
- ];
|
|
|
-
|
|
|
- electronApi.spawnExec(params).then(async (res) => {
|
|
|
- // 生成平铺水印图片
|
|
|
- if(this.handleData.watermarkStyle == 2){ // 平铺
|
|
|
- let tmpPath2 = os.tmpdir()+separator+'water_pu_'+index+'.png';
|
|
|
- let params2 = [
|
|
|
- 'convert.exe',
|
|
|
- '-monitor',
|
|
|
- tmpPath,
|
|
|
- '-write',
|
|
|
- 'mpr:tiler',
|
|
|
- '+delete',
|
|
|
- '-size',
|
|
|
- imgInfo.width+'x'+imgInfo.height,
|
|
|
- 'tile:mpr:tiler',
|
|
|
- tmpPath2
|
|
|
- ];
|
|
|
- await electronApi.spawnExec(params2,{stderr:(data) => { if(this.menuIndex == '1') {imgInfo.percent=60;this.imgList.splice(index,1,imgInfo);}}}).then(async (res2) => {
|
|
|
- await this.waterComposite(index, imgInfo, newPath, tmpPath2, isPreview);
|
|
|
- })
|
|
|
- }else{
|
|
|
- await this.waterComposite(index, imgInfo, newPath, tmpPath, isPreview);
|
|
|
- }
|
|
|
-
|
|
|
- resolve({type:this.menuIndex, index:index, info:imgInfo});
|
|
|
- }).catch(err => {
|
|
|
- reject({type:this.menuIndex, index:index, err: err});
|
|
|
- });
|
|
|
- });
|
|
|
- },
|
|
|
- async waterComposite(index, imgInfo, newPath, waterImg, isPreview){
|
|
|
- if(isPreview){ // 预览状态
|
|
|
- newPath = this.previewTmpPath
|
|
|
- }
|
|
|
-
|
|
|
- let watermarkX = this.handleData.watermarkX;
|
|
|
- let watermarkY = this.handleData.watermarkY;
|
|
|
-
|
|
|
- //解决 兼容PDF和预览的图片的水印位置一致的问题
|
|
|
- if(this.handleData.watermarkPosition == 'East' || this.handleData.watermarkPosition == 'NorthEast' || this.handleData.watermarkPosition == 'SouthEast'){
|
|
|
- if(this.menuIndex == '2'){
|
|
|
- watermarkX = -watermarkX;
|
|
|
- }
|
|
|
- }
|
|
|
- if(this.handleData.watermarkPosition == 'SouthWest' || this.handleData.watermarkPosition == 'South' || this.handleData.watermarkPosition == 'SouthEast'){
|
|
|
- if(this.menuIndex == '2'){
|
|
|
- watermarkY = -watermarkY;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- let waterParams = [];
|
|
|
- if(this.menuIndex == '2' && this.handleData.watermarkStyle == 3 && this.watermarkImgList.length > 0){
|
|
|
- for(let iw = 0; iw < this.watermarkImgList.length; iw ++){
|
|
|
- let witem = this.watermarkImgList[iw];
|
|
|
- if(witem.watermarkImgPath){
|
|
|
- witem['tmpPath'] = os.tmpdir()+separator+'water_pdf_'+iw+'.png';
|
|
|
- let params = [
|
|
|
- 'convert.exe',
|
|
|
- '-monitor',
|
|
|
- '-background',
|
|
|
- 'none',
|
|
|
- '-resize',
|
|
|
- `${Number(witem.scaling)}%`,
|
|
|
- '-alpha', 'set', '-channel', 'A', '-evaluate', 'Multiply', witem.watermarkImgOpactiy/100, '+channel', // 透明度
|
|
|
- '-rotate',
|
|
|
- witem.rotate ? witem.rotate : 0,
|
|
|
- '-gravity',
|
|
|
- 'center',
|
|
|
- '-extent',
|
|
|
- '100%',
|
|
|
- witem.watermarkImgPath,
|
|
|
- witem['tmpPath']
|
|
|
- ];
|
|
|
-
|
|
|
- await electronApi.spawnExec(params).then(async (res) => {
|
|
|
- let arr = [
|
|
|
- witem['tmpPath'],
|
|
|
- '-gravity',
|
|
|
- witem.watermarkPosition,
|
|
|
- '-geometry',
|
|
|
- '+' + witem.watermarkX + '+' + witem.watermarkY,
|
|
|
- '-composite'
|
|
|
- ];
|
|
|
- waterParams = waterParams.concat(arr);
|
|
|
- });
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- let params2 = [
|
|
|
- 'convert.exe',
|
|
|
- '-monitor',
|
|
|
- imgInfo.path,
|
|
|
- waterImg,
|
|
|
- '-gravity',
|
|
|
- this.handleData.watermarkStyle == 2 ? 'Center' : this.handleData.watermarkPosition,
|
|
|
- '-geometry',
|
|
|
- '+' + watermarkX + '+' + watermarkY,
|
|
|
- '-composite',
|
|
|
- ...waterParams,
|
|
|
- newPath
|
|
|
- ];
|
|
|
-
|
|
|
- await electronApi.spawnExec(params2,{
|
|
|
- stderr:(data) => {
|
|
|
- let percent = 0;
|
|
|
- let str = data.toString();
|
|
|
- const regexDuration = /Load.*?,(.*?)%/;
|
|
|
- const regexDuration2 = /Resize.*?,(.*?)%/;
|
|
|
-
|
|
|
- const res = regexDuration.exec(str);
|
|
|
- const res2 = regexDuration2.exec(str);
|
|
|
-
|
|
|
- let p1 = 0;
|
|
|
- let p2 = 0;
|
|
|
- if(res && res[1]){
|
|
|
- p1 = parseInt(res[1]);
|
|
|
- if(p1 > 0){
|
|
|
- imgInfo.percent = Math.round(p1/2);
|
|
|
- }
|
|
|
- }else{
|
|
|
- if(res2 && res2[1]){
|
|
|
- p2 = parseInt(res2[1]);
|
|
|
- }
|
|
|
- if(p2 > 0){
|
|
|
- imgInfo.percent = Math.round(50+(p2/2));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if(this.handleData.watermarkStyle == 2){ // 平铺
|
|
|
- imgInfo.percent = 60 + Math.round(percent*0.4);
|
|
|
- }else{
|
|
|
- imgInfo.percent = percent;
|
|
|
- }
|
|
|
-
|
|
|
- if(this.menuIndex == '1' && this.imgList[index]){
|
|
|
- this.imgList.splice(index,1,imgInfo);
|
|
|
- }
|
|
|
- },
|
|
|
- }).then(res2 => {
|
|
|
- setTimeout(() => {
|
|
|
- if(this.menuIndex == '1' && this.imgList[index]){
|
|
|
- imgInfo.percent = 100;
|
|
|
- this.imgList.splice(index, 1, imgInfo);
|
|
|
- }
|
|
|
- }, 100)
|
|
|
-
|
|
|
- if(isPreview){ // 预览状态
|
|
|
- electronApi.fileStream(newPath).then(buffer => {
|
|
|
- this.imgSrc = "data:image/png;base64,"+buffer.toString('base64');
|
|
|
- this.imgLoading = false;
|
|
|
- }).catch(err => {
|
|
|
- this.imgLoading = false;
|
|
|
- })
|
|
|
- }else{
|
|
|
- //未购买 添加系统水印
|
|
|
- this.addWatermark(index,{...imgInfo,path:newPath},newPath);
|
|
|
- }
|
|
|
- });
|
|
|
- },
|
|
|
- hexify(color) {
|
|
|
- var values = color
|
|
|
- .replace(/rgba?\(/, '')
|
|
|
- .replace(/\)/, '')
|
|
|
- .replace(/[\s+]/g, '')
|
|
|
- .split(',');
|
|
|
-
|
|
|
- var a = parseFloat(values[3] || 1),
|
|
|
- r = Math.floor(a * parseInt(values[0]) + (1 - a) * 255),
|
|
|
- g = Math.floor(a * parseInt(values[1]) + (1 - a) * 255),
|
|
|
- b = Math.floor(a * parseInt(values[2]) + (1 - a) * 255);
|
|
|
- return "#" +
|
|
|
- ("0" + r.toString(16)).slice(-2) +
|
|
|
- ("0" + g.toString(16)).slice(-2) +
|
|
|
- ("0" + b.toString(16)).slice(-2);
|
|
|
- },
|
|
|
// 初始化系统水印图片
|
|
|
async initSysWater(imgInfo){
|
|
|
return new Promise((resolve,reject) => {
|
|
|
let fontSize = 40;
|
|
|
let width = imgInfo.width;
|
|
|
- if(this.menuIndex == '3'){
|
|
|
- width = width * (this.handleData.scaling / 100);
|
|
|
- }
|
|
|
if (width < 500) {
|
|
|
fontSize = 16;
|
|
|
} else if (width < 1000) {
|
|
@@ -965,7 +716,7 @@ export default {
|
|
|
}else if(width < 2000){
|
|
|
fontSize = 40;
|
|
|
}else{
|
|
|
- fontSize = 100;
|
|
|
+ fontSize = 130;
|
|
|
}
|
|
|
|
|
|
let sysDefaultTmpPath = os.tmpdir()+separator+'water_sys_'+fontSize+'.png';
|
|
@@ -973,15 +724,15 @@ export default {
|
|
|
let params = [
|
|
|
'convert.exe',
|
|
|
'-monitor',
|
|
|
+ '-background',
|
|
|
+ 'none',
|
|
|
'-fill',
|
|
|
- 'red',
|
|
|
+ 'black',
|
|
|
'-font',
|
|
|
this.defaultFont,
|
|
|
'-pointsize',
|
|
|
fontSize,
|
|
|
- '-background',
|
|
|
- 'none',
|
|
|
- 'label:https://www.xingyousoft.com',
|
|
|
+ 'label:from:https://www.xingyousoft.com',
|
|
|
sysDefaultTmpPath
|
|
|
];
|
|
|
|
|
@@ -997,11 +748,15 @@ export default {
|
|
|
});
|
|
|
},
|
|
|
// 添加默认水印
|
|
|
- async addWatermark(index,imgInfo,newPath) {
|
|
|
+ async addWatermark(index, imgInfo, res, newPath) {
|
|
|
return new Promise((resolve,reject) => {
|
|
|
let authority = this.$refs.headerRef.authority;
|
|
|
|
|
|
if (authority.isAuthority) {
|
|
|
+ fs.copyFileSync(res, newPath);
|
|
|
+ if(fs.existsSync(newPath)){
|
|
|
+ fs.unlinkSync(res);
|
|
|
+ }
|
|
|
// 有权限,则不做任何操作
|
|
|
resolve(true)
|
|
|
} else {
|
|
@@ -1011,12 +766,10 @@ export default {
|
|
|
let params2 = [
|
|
|
'convert.exe',
|
|
|
'-monitor',
|
|
|
- newPath,
|
|
|
- '-compose','over',
|
|
|
+ res,
|
|
|
sysDefaultTmpPath,
|
|
|
'-gravity',
|
|
|
'center',
|
|
|
- '-type','trueColorAlpha',
|
|
|
'-composite',
|
|
|
newPath
|
|
|
];
|
|
@@ -1053,7 +806,8 @@ export default {
|
|
|
if(fs.existsSync(w4)){
|
|
|
fs.unlinkSync(w4);
|
|
|
}
|
|
|
- }
|
|
|
+ },
|
|
|
+
|
|
|
}
|
|
|
};
|
|
|
</script>
|