Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Q
qk_backend
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
quanku
qk_backend
Commits
98091597
Commit
98091597
authored
Aug 22, 2024
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片旋转处理
parent
5d33e647
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
511 additions
and
3 deletions
+511
-3
ch-admin-api/src/main/java/com/wwdz/ch/admin/controller/AdminStorageController.java
.../com/wwdz/ch/admin/controller/AdminStorageController.java
+19
-1
ch-core/src/main/java/com/wwdz/ch/core/util/ImgUtil.java
ch-core/src/main/java/com/wwdz/ch/core/util/ImgUtil.java
+420
-0
ch-core/src/main/java/com/wwdz/ch/core/util/RandomUtil.java
ch-core/src/main/java/com/wwdz/ch/core/util/RandomUtil.java
+41
-0
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
...pi/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
+13
-1
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxStorageController.java
...src/main/java/com/wwdz/ch/wx/web/WxStorageController.java
+18
-1
No files found.
ch-admin-api/src/main/java/com/wwdz/ch/admin/controller/AdminStorageController.java
View file @
98091597
...
...
@@ -14,6 +14,7 @@ import com.wwdz.ch.admin.service.UploadService;
import
com.wwdz.ch.admin.util.AuthSupport
;
import
com.wwdz.ch.core.storage.StorageService
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.ImgUtil
;
import
com.wwdz.ch.core.util.MediaUtil
;
import
com.wwdz.ch.core.util.ResponseUtil
;
import
com.wwdz.ch.core.validator.Order
;
...
...
@@ -31,8 +32,11 @@ import org.springframework.web.bind.annotation.*;
import
org.springframework.web.multipart.MultipartFile
;
import
sun.misc.BASE64Encoder
;
import
javax.imageio.ImageIO
;
import
javax.validation.constraints.NotNull
;
import
java.awt.image.BufferedImage
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -74,7 +78,21 @@ public class AdminStorageController {
String
originalFilename
=
file
.
getOriginalFilename
();
long
nowTime
=
System
.
currentTimeMillis
();
String
name
=
new
BASE64Encoder
().
encode
(
Long
.
toString
(
nowTime
).
getBytes
())
+
RandomUtil
.
randomInt
(
1000
);
String
url
=
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
InputStream
targetInput
=
null
;
try
(
InputStream
inputStream
=
file
.
getInputStream
())
{
BufferedImage
image
=
ImageIO
.
read
(
inputStream
);
ImgUtil
.
ImageOrientationWithNameResult
orientationResult
=
ImgUtil
.
getImageFileNameWithWithRepaintInfo
(
file
,
image
,
null
);
name
=
orientationResult
.
getImageName
();
if
(
orientationResult
.
getNeedRepaint
())
{
logger
.
info
(
"当前图片需要进行重绘,旋转角度:【{}】"
,
orientationResult
.
getAngel
());
targetInput
=
ImgUtil
.
repaintImage2InputStream
(
image
,
orientationResult
.
getAngel
(),
orientationResult
.
getType
());
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"get image size failed : "
,
e
);
}
String
url
=
storageService
.
store
(
targetInput
,
file
.
getSize
(),
file
.
getContentType
(),
name
,
MediaUtil
.
isRotation
(
file
));
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
data
.
put
(
"url"
,
url
);
...
...
ch-core/src/main/java/com/wwdz/ch/core/util/ImgUtil.java
0 → 100644
View file @
98091597
This diff is collapsed.
Click to expand it.
ch-core/src/main/java/com/wwdz/ch/core/util/RandomUtil.java
0 → 100644
View file @
98091597
package
com.wwdz.ch.core.util
;
import
java.security.SecureRandom
;
public
class
RandomUtil
{
private
static
final
SecureRandom
RANDOM
=
new
SecureRandom
();
/**
* 获取随机20长度字符串
*
* @return 随机字符串
*/
public
static
String
getRandom20Str
()
{
return
getRandomStr
(
20
);
}
/**
* 获取随机字符串
*
* @param length 字符串长度
* @return 随机字符串
*/
public
static
String
getRandomStr
(
int
length
)
{
return
UUID
.
randomUUID
().
toString
().
replaceAll
(
"-"
,
""
).
substring
(
0
,
length
);
}
/**
* 获取随机int值
*
* @param broad 边界
* @return int随机值
*/
public
static
int
getRandomInt
(
int
broad
){
return
RANDOM
.
nextInt
(
broad
);
}
public
static
int
getRandomInt
(){
return
RANDOM
.
nextInt
();
}
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
View file @
98091597
...
...
@@ -10,6 +10,7 @@ import com.wwdz.ch.core.storage.StorageService;
import
com.wwdz.ch.core.type.PageSearchResult
;
import
com.wwdz.ch.core.type.Result
;
import
com.wwdz.ch.core.util.CacheUtil
;
import
com.wwdz.ch.core.util.ImgUtil
;
import
com.wwdz.ch.core.util.MediaUtil
;
import
com.wwdz.ch.db.bean.EsPageInfo
;
import
com.wwdz.ch.db.bean.ItemOfEs
;
...
...
@@ -1116,9 +1117,20 @@ public class ItemServiceImpl implements ItemService {
InputStream imageStream = bufferedImageToInputStream(bufferedImage, lastKey.substring(1));
qiniuStorage.store(imageStream, file.getSize(), file.getContentType(), keyName);*/
InputStream
targetInput
=
null
;
try
(
InputStream
inputStream
=
file
.
getInputStream
())
{
BufferedImage
image
=
ImageIO
.
read
(
inputStream
);
ImgUtil
.
ImageOrientationWithNameResult
orientationResult
=
ImgUtil
.
getImageFileNameWithWithRepaintInfo
(
file
,
image
,
null
);
if
(
orientationResult
.
getNeedRepaint
())
{
logger
.
info
(
"当前图片需要进行重绘,旋转角度:【{}】"
,
orientationResult
.
getAngel
());
targetInput
=
ImgUtil
.
repaintImage2InputStream
(
image
,
orientationResult
.
getAngel
(),
orientationResult
.
getType
());
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"get image size failed : "
,
e
);
}
String
originalFilename
=
file
.
getOriginalFilename
();
String
url
=
storageService
.
store
(
file
.
getInputStream
()
,
file
.
getSize
(),
file
.
getContentType
(),
originalFilename
,
MediaUtil
.
isRotation
(
file
));
String
url
=
storageService
.
store
(
targetInput
,
file
.
getSize
(),
file
.
getContentType
(),
originalFilename
,
MediaUtil
.
isRotation
(
file
));
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"url"
,
url
);
return
Result
.
success
(
map
);
...
...
ch-wx-api/src/main/java/com/wwdz/ch/wx/web/WxStorageController.java
View file @
98091597
...
...
@@ -3,6 +3,7 @@ package com.wwdz.ch.wx.web;
import
com.alibaba.fastjson.JSONObject
;
import
com.wwdz.ch.core.storage.StorageService
;
import
com.wwdz.ch.core.util.CharUtil
;
import
com.wwdz.ch.core.util.ImgUtil
;
import
com.wwdz.ch.core.util.MediaUtil
;
import
com.wwdz.ch.core.util.ResponseUtil
;
import
com.wwdz.ch.db.dao.dts.DtsStorageDao
;
...
...
@@ -22,6 +23,8 @@ import org.springframework.validation.annotation.Validated;
import
org.springframework.web.bind.annotation.*
;
import
org.springframework.web.multipart.MultipartFile
;
import
javax.imageio.ImageIO
;
import
java.awt.image.BufferedImage
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.util.*
;
...
...
@@ -78,7 +81,21 @@ public class WxStorageController {
logger
.
info
(
"【请求开始】上传文件,请求参数,file:{}"
,
file
.
getOriginalFilename
());
String
originalFilename
=
file
.
getOriginalFilename
();
String
url
=
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
InputStream
targetInput
=
null
;
try
(
InputStream
inputStream
=
file
.
getInputStream
())
{
BufferedImage
image
=
ImageIO
.
read
(
inputStream
);
ImgUtil
.
ImageOrientationWithNameResult
orientationResult
=
ImgUtil
.
getImageFileNameWithWithRepaintInfo
(
file
,
image
,
null
);
if
(
orientationResult
.
getNeedRepaint
())
{
logger
.
info
(
"当前图片需要进行重绘,旋转角度:【{}】"
,
orientationResult
.
getAngel
());
targetInput
=
ImgUtil
.
repaintImage2InputStream
(
image
,
orientationResult
.
getAngel
(),
orientationResult
.
getType
());
}
}
catch
(
Exception
e
)
{
logger
.
error
(
"get image size failed : "
,
e
);
}
String
url
=
storageService
.
store
(
targetInput
,
file
.
getSize
(),
file
.
getContentType
(),
originalFilename
,
MediaUtil
.
isRotation
(
file
));
Map
<
String
,
Object
>
data
=
new
HashMap
<>();
...
...
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