Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lakernote
EasyAdmin
提交
897fcf5a
E
EasyAdmin
项目概览
lakernote
/
EasyAdmin
8 个月 前同步成功
通知
14
Star
3
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
EasyAdmin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
897fcf5a
编写于
9月 07, 2021
作者:
lakernote
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
(add)[整体](增加缩略图接口)
上级
630f4468
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
104 addition
and
2 deletion
+104
-2
pom.xml
pom.xml
+6
-0
src/main/java/com/laker/admin/config/WebMvcConfig.java
src/main/java/com/laker/admin/config/WebMvcConfig.java
+2
-1
src/main/java/com/laker/admin/framework/utils/EasyImageUtils.java
.../java/com/laker/admin/framework/utils/EasyImageUtils.java
+41
-0
src/main/java/com/laker/admin/module/sys/controller/IndexController.java
...om/laker/admin/module/sys/controller/IndexController.java
+36
-1
src/test/java/com/laker/admin/service/EasyImageUtilsTest.java
...test/java/com/laker/admin/service/EasyImageUtilsTest.java
+19
-0
未找到文件。
pom.xml
浏览文件 @
897fcf5a
...
...
@@ -161,6 +161,12 @@
<artifactId>
nginxparser
</artifactId>
<version>
0.9.6
</version>
</dependency>
<!-- 图片处理 -->
<dependency>
<groupId>
net.coobird
</groupId>
<artifactId>
thumbnailator
</artifactId>
<version>
0.4.14
</version>
</dependency>
</dependencies>
<build>
...
...
src/main/java/com/laker/admin/config/WebMvcConfig.java
浏览文件 @
897fcf5a
...
...
@@ -34,7 +34,8 @@ public class WebMvcConfig implements WebMvcConfigurer {
"/error"
,
"/swagger-resources/**"
,
"/api/v1/login"
,
"/captcha"
);
"/captcha"
,
"/thumbnail"
);
}
@Override
...
...
src/main/java/com/laker/admin/framework/utils/EasyImageUtils.java
0 → 100644
浏览文件 @
897fcf5a
package
com.laker.admin.framework.utils
;
import
net.coobird.thumbnailator.Thumbnails
;
import
java.io.IOException
;
import
java.io.OutputStream
;
import
java.net.URL
;
/**
* @author laker
* 图片处理类
*/
public
class
EasyImageUtils
{
/**
* 按照宽高尺寸压缩图片,
*
* @param sourceUrl 图片url
* @param out 输出的流 预览流
* @param width
* @param height
* @throws IOException
*/
public
static
void
compressBysize
(
String
sourceUrl
,
OutputStream
out
,
int
width
,
int
height
)
throws
IOException
{
Thumbnails
.
of
(
new
URL
(
sourceUrl
))
.
width
(
width
)
.
height
(
height
)
.
toOutputStream
(
out
);
}
public
static
void
scale
(
String
source
,
String
out
,
double
scale
)
throws
IOException
{
Thumbnails
.
of
(
source
)
.
scale
(
scale
)
.
size
(
100
,
100
)
.
toFile
(
out
);
}
}
src/main/java/com/laker/admin/module/sys/controller/IndexController.java
浏览文件 @
897fcf5a
package
com.laker.admin.module.sys.controller
;
import
cn.hutool.core.io.FileUtil
;
import
cn.hutool.core.lang.Dict
;
import
cn.hutool.core.util.IdUtil
;
import
com.laker.admin.framework.model.Response
;
import
com.laker.admin.framework.cache.ICache
;
import
com.laker.admin.framework.model.Response
;
import
com.laker.admin.framework.utils.EasyImageUtils
;
import
com.wf.captcha.ArithmeticCaptcha
;
import
lombok.extern.slf4j.Slf4j
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Controller
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.RequestParam
;
import
org.springframework.web.bind.annotation.ResponseBody
;
import
javax.servlet.http.HttpServletResponse
;
import
java.io.BufferedOutputStream
;
import
java.io.IOException
;
import
java.io.OutputStream
;
/**
* /admin/** 无需check login
*/
...
...
@@ -50,4 +58,31 @@ public class IndexController {
return
Response
.
ok
(
Dict
.
create
().
set
(
"uid"
,
uid
).
set
(
"image"
,
captcha
.
toBase64
()));
}
/**
* 缩略图
* http://localhost:8080/thumbnail?url=http://localhost:8080/admin/admin/images/wx.jpg
*/
@GetMapping
(
"/thumbnail"
)
public
void
thumbnail
(
String
url
,
HttpServletResponse
response
,
@RequestParam
(
required
=
false
,
defaultValue
=
"1"
)
int
type
,
@RequestParam
(
required
=
false
,
defaultValue
=
"100"
)
int
width
,
@RequestParam
(
required
=
false
,
defaultValue
=
"100"
)
int
height
)
throws
IOException
{
OutputStream
out
=
new
BufferedOutputStream
(
response
.
getOutputStream
());
switch
(
type
)
{
case
1
:
// 预览
response
.
setContentType
(
"image/"
+
FileUtil
.
getSuffix
(
url
)
+
"; charset=utf-8"
);
break
;
case
2
:
// 下载
response
.
addHeader
(
"Content-Disposition"
,
"attachment;filename="
+
new
String
(
FileUtil
.
mainName
(
url
).
getBytes
(
"utf-8"
),
"iso-8859-1"
)
+
"."
+
FileUtil
.
getSuffix
(
url
));
response
.
setContentType
(
"application/octet-stream"
);
break
;
default
:
response
.
setContentType
(
"image/"
+
FileUtil
.
getSuffix
(
url
)
+
"; charset=utf-8"
);
}
EasyImageUtils
.
compressBysize
(
url
,
out
,
width
,
height
);
}
}
\ No newline at end of file
src/test/java/com/laker/admin/service/EasyImageUtilsTest.java
0 → 100644
浏览文件 @
897fcf5a
package
com.laker.admin.service
;
import
net.coobird.thumbnailator.Thumbnails
;
import
java.io.IOException
;
public
class
EasyImageUtilsTest
{
public
static
void
main
(
String
[]
args
)
throws
IOException
{
size
(
"d://1.jpg"
,
"d://laker_200x300.jpg"
);
}
public
static
void
size
(
String
source
,
String
out
)
throws
IOException
{
Thumbnails
.
of
(
source
)
.
size
(
100
,
100
)
.
toFile
(
out
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录