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
61a0448d
Commit
61a0448d
authored
Aug 22, 2024
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片旋转
parent
42b46074
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
4 deletions
+49
-4
ch-core/src/main/java/com/wwdz/ch/core/storage/StorageService.java
...rc/main/java/com/wwdz/ch/core/storage/StorageService.java
+39
-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
+10
-4
No files found.
ch-core/src/main/java/com/wwdz/ch/core/storage/StorageService.java
View file @
61a0448d
...
...
@@ -10,6 +10,7 @@ import com.drew.imaging.ImageMetadataReader;
import
com.drew.metadata.Directory
;
import
com.drew.metadata.Metadata
;
import
com.drew.metadata.MetadataException
;
import
com.drew.metadata.exif.ExifDirectoryBase
;
import
com.drew.metadata.exif.ExifIFD0Directory
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.consts.MediaTypeEnum
;
...
...
@@ -91,6 +92,7 @@ public class StorageService {
}
String
type
=
MediaTypeEnum
.
getByMime
(
contentType
)
==
null
?
MediaTypeEnum
.
IMAGE_JPG
.
getExt
()
:
MediaTypeEnum
.
getByMime
(
contentType
).
getExt
();
String
keyName
;
//宽x高
if
(
rotation
)
{
keyName
=
CommConsts
.
UPLOAD_PRE_DIRECTORY
+
CommonUtils
.
getUUID
()
+
"_"
+
bufferedImage
.
getHeight
()
+
"x"
+
bufferedImage
.
getWidth
()
+
"."
+
type
;
}
else
{
...
...
@@ -137,4 +139,41 @@ public class StorageService {
return
storage
.
generateUrl
(
keyName
);
}
/*public static ImgWH getImgWH(InputStream inputStream) {
try {
Image img = ImageIO.read(file);
wh.setWidth(img.getWidth(null));
wh.setHeight(img.getHeight(null));
//检查是否有旋转角度导致ImageIO获取宽高相反
Metadata metadata = ImageMetadataReader.readMetadata(inputStream);
StringBuilder description = new StringBuilder();
metadata.getDirectories().forEach(directory -> {
directory.getTags().forEach(tag -> {
if (tag.getTagType() == ExifDirectoryBase.TAG_ORIENTATION) {
description.append(tag.getDescription().replaceAll(" ", ""));
}
});
});
if (description.length() > 0) {
int rotateIndex = description.indexOf("Rotate");
int cwIndex = description.indexOf("CW");
if (rotateIndex >= 0 && cwIndex > 0 && rotateIndex < cwIndex) {
int angel = Integer.parseInt(description.substring(rotateIndex + 6, cwIndex));
if (angel == 90 || angel == 180) {
//宽高互换
int t = wh.getHeight();
wh.setHeight(wh.getWidth());
wh.setWidth(t);
}
}
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return wh;
}*/
}
ch-wx-api/src/main/java/com/wwdz/ch/wx/impl/ItemServiceImpl.java
View file @
61a0448d
...
...
@@ -6,6 +6,7 @@ import com.github.pagehelper.PageInfo;
import
com.qiniu.storage.model.FileInfo
;
import
com.wwdz.ch.core.consts.*
;
import
com.wwdz.ch.core.storage.QiniuStorage
;
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
;
...
...
@@ -149,6 +150,9 @@ public class ItemServiceImpl implements ItemService {
@Autowired
ConsignSaleService
consignSaleService
;
@Autowired
private
StorageService
storageService
;
@Override
public
Result
nameList
(
ItemRequestDto
dto
)
{
try
{
...
...
@@ -1104,16 +1108,18 @@ public class ItemServiceImpl implements ItemService {
try
{
InputStream
inputStream
=
file
.
getInputStream
();
BufferedImage
bufferedImage
=
ImageIO
.
read
(
inputStream
);
String
lastKey
=
".jpg"
;
/*
String lastKey = ".jpg";
if (StringUtils.isNotBlank(file.getOriginalFilename())) {
lastKey = file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf("."));
}
String keyName = CommConsts.UPLOAD_PRE_DIRECTORY + CommonUtils.getUUID() + "_" + bufferedImage.getWidth() + "x" + bufferedImage.getHeight() + lastKey;
InputStream imageStream = bufferedImageToInputStream(bufferedImage, lastKey.substring(1));
qiniuStorage
.
store
(
imageStream
,
file
.
getSize
(),
file
.
getContentType
(),
keyName
);
String
urlOfSize
=
qiniuStorage
.
generateUrl
(
keyName
);
qiniuStorage.store(imageStream, file.getSize(), file.getContentType(), keyName);*/
String
originalFilename
=
file
.
getOriginalFilename
();
String
url
=
storageService
.
store
(
file
.
getInputStream
(),
file
.
getSize
(),
file
.
getContentType
(),
originalFilename
);
Map
<
String
,
Object
>
map
=
new
HashMap
<>();
map
.
put
(
"url"
,
url
OfSize
);
map
.
put
(
"url"
,
url
);
return
Result
.
success
(
map
);
}
catch
(
Exception
e
)
{
logger
.
error
(
"图片上传七牛云失败,原因:"
+
e
.
getMessage
(),
e
);
...
...
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