Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Shenlin
/
publisher
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Shenlin
2016-11-04 10:16:49 +0800
Browse Files
Options
Browse Files
Download
Plain Diff
Commit
47a4e4b08606a980b12c757373773300175ca02c
47a4e4b0
2 parents
2a9f3113
53db8a1e
Merge branch 'develop' into 'master'
优化图片 See merge request
!1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
22 deletions
index.html
server/init/config.js
server/lib/uploader.js
index.html
View file @
47a4e4b
...
...
@@ -73,16 +73,16 @@
$editor
.
summernote
({
height
:
500
,
// set editor height
minHeight
:
300
,
// set minimum height of editor
maxHeight
:
760
,
// set maximum height of editor
//
maxHeight: 760, // set maximum height of editor
focus
:
true
,
// set focus to editable area after initializing summernote
lang
:
'zh-CN'
,
placeholder
:
'写点什么...'
,
toolbar
:
[
[
'font'
,
[
'fontname'
,
'fontsize'
,
'color'
]],
[
'font-style'
,
[
'bold'
,
'italic'
,
'underline'
,
'strikethrough'
,
'subscript'
,
'superscript'
]],
[
'para'
,
[
'style'
,
'paragraph'
,
'height'
]],
[
'media'
,
[
'gallery'
,
'picture'
,
'link'
,
'video'
]],
[
'insert'
,
[
'table'
,
'hr'
,
'ol'
,
'ul'
]],
[
'para'
,
[
'style'
,
'paragraph'
,
'height'
]],
[
'misc'
,
[
'clear'
,
'undo'
,
'redo'
]],
[
'send'
,
[
'publish'
]],
[
'tools'
,
[
'fullscreen'
,
'codeview'
,
'help'
]]
...
...
@@ -116,7 +116,12 @@
var
file
=
result
.
content
.
files
[
0
]
||
{};
console
.
log
(
file
);
if
(
file
.
size
)
{
$editor
.
summernote
(
'insertImage'
,
'http://domino.chuangcheng.co/appimg/000151418f2f4b82b924649fccd47eb5_1vuy5a.jpg'
,
file
.
name
);
setTimeout
(
function
()
{
$editor
.
summernote
(
'insertImage'
,
file
.
url
,
function
(
$image
)
{
$image
.
css
(
'width'
,
$image
.
width
()
/
3
);
$image
.
attr
(
'data-filename'
,
file
.
name
);
});
},
1000
);
//等待上传处理图片
}
}
});
...
...
server/init/config.js
View file @
47a4e4b
...
...
@@ -103,7 +103,7 @@ var configure = function () {
//文件上传目录定义
upload
:
{
root
:
'/opt/domino-img/'
,
base_url
:
BASE_URL
,
base_url
:
null
,
appimg
:
'appimg/'
,
qrimg
:
'qrimg/'
,
wximg
:
'wximg/'
...
...
server/lib/uploader.js
View file @
47a4e4b
...
...
@@ -23,9 +23,11 @@ module.exports = function Uploader(routerPath, db) {
const
DEST_DIR
=
path
.
resolve
(
UPLOAD_OPTION
.
root
,
routerPath
),
IMAGE_URL
=
UPLOAD_OPTION
.
base_url
+
routerPath
+
'/'
,
THUMB_W
=
240
,
THUMB_H
=
240
;
IMAGE_URL
=
UPLOAD_OPTION
.
base_url
||
'/'
+
routerPath
+
'/'
,
THUMB_WIDTH
=
240
;
//定义上传文件的访问路径
router
.
use
(
`/
${
routerPath
}
`
,
express
.
static
(
DEST_DIR
));
// var FileInfo = db.import(path.resolve(ENTITIES_PATH, 'file_info'));
...
...
@@ -41,30 +43,32 @@ module.exports = function Uploader(routerPath, db) {
/**
* 创建缩略图
* @param gm_object gm对象,可以在此前对图片做好预处理
* @param file
处理图片文件
* @param file
_orig 原始
处理图片文件
* @param uploaded_file 上传文件结构
*/
var
create_thumb
=
function
(
gm_object
,
file
,
uploaded_file
)
{
let
dest_thumb
=
uploaded_file
.
thumb_path
,
dest_file
=
uploaded_file
.
file_path
;
var
create_thumb
=
function
(
gm_object
,
file_orig
,
uploaded_file
)
{
let
dest_thumb
=
uploaded_file
.
thumb_path
,
//缩略图
dest_file
=
uploaded_file
.
file_path
,
//优化后的图片
dest_orig
=
uploaded_file
.
orig_path
;
//原始图片
gm_object
.
size
(
function
(
err
,
size
)
{
if
(
err
)
{
logger
.
error
(
err
,
uploaded_file
);
return
;
}
if
(
size
.
width
>
THUMB_W
||
size
.
height
>
THUMB_H
)
{
this
.
thumb
(
THUMB_W
,
THUMB_H
,
dest_thumb
,
0
,
'center'
,
function
(
err
)
{
err
?
logger
.
error
(
err
,
uploaded_file
)
:
logger
.
debug
(
'image saved to'
,
uploaded_file
);
//move file to dest_path
fs
.
rename
(
file
.
path
,
dest_file
);
});
this
.
write
(
dest_file
,
function
(
err
)
{
if
(
err
)
{
logger
.
error
(
err
,
uploaded_file
);
}
else
{
//小图片直接复制
this
.
write
(
dest_thumb
,
function
(
err
)
{
let
thumb_w
=
size
.
width
>
size
.
height
?
size
.
height
:
size
.
width
;
//计算最小边作为缩略图
thumb_w
=
thumb_w
>
THUMB_WIDTH
?
THUMB_WIDTH
:
thumb_w
;
gm
(
dest_file
).
thumb
(
thumb_w
,
thumb_w
,
dest_thumb
,
0
,
'center'
,
function
(
err
)
{
err
?
logger
.
error
(
err
,
uploaded_file
)
:
logger
.
debug
(
'image saved to'
,
uploaded_file
);
//move file to dest_path
fs
.
rename
(
file
.
path
,
dest_file
);
})
//move file to dest_orig
fs
.
rename
(
file_orig
.
path
,
dest_orig
);
});
}
})
});
};
...
...
@@ -83,7 +87,7 @@ module.exports = function Uploader(routerPath, db) {
if
(
files
.
hasOwnProperty
(
key
))
{
let
file
=
files
[
key
];
if
(
file
&&
file
.
size
)
{
let
file_ext
=
file
.
type
.
replace
(
'image/'
,
''
);
let
file_ext
=
file
.
type
.
replace
(
'image/'
,
''
)
,
orig_ext
=
file_ext
;
switch
(
file
.
type
)
{
case
'image/gif'
:
file_ext
=
'gif'
;
...
...
@@ -103,7 +107,9 @@ module.exports = function Uploader(routerPath, db) {
salt
=
(
~~
(
Math
.
random
()
*
1000000000
)).
toString
(
36
),
file_id
=
crypto_utils
.
UUID
(),
file_name
=
`
${
file_id
}
_
${
salt
}
.
${
file_ext
}
`
,
orig_file_name
=
`
${
file_id
}
_
${
salt
}
_o.
${
orig_ext
}
`
,
dest_file
=
path
.
resolve
(
DEST_DIR
,
file_name
),
dest_orig
=
path
.
resolve
(
DEST_DIR
,
orig_file_name
),
dest_thumb
=
dest_file
.
replace
(
regexp
,
'_s.$1'
),
uploaded_file
=
{
id
:
file_id
,
...
...
@@ -112,6 +118,7 @@ module.exports = function Uploader(routerPath, db) {
size
:
file
.
size
,
file_path
:
dest_file
,
thumb_path
:
dest_thumb
,
orig_path
:
dest_orig
,
hash
:
file
.
hash
,
url
:
IMAGE_URL
+
file_name
,
params
:
fields
,
...
...
Please
register
or
login
to post a comment