Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
a597bf9f
Commit
a597bf9f
authored
Aug 09, 2021
by
蒋勇
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
surport png2jpg
parent
c87b2c9b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
53 additions
and
0 deletions
+53
-0
scratch-web/app/base/api/impl/imghandle.js
+53
-0
No files found.
scratch-web/app/base/api/impl/imghandle.js
View file @
a597bf9f
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment