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
a893a80f
Commit
a893a80f
authored
Aug 22, 2024
by
shiyu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
图片旋转
parent
0da719a4
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
13 deletions
+33
-13
ch-core/pom.xml
ch-core/pom.xml
+5
-0
ch-core/src/main/java/com/wwdz/ch/core/storage/StorageService.java
...rc/main/java/com/wwdz/ch/core/storage/StorageService.java
+28
-13
No files found.
ch-core/pom.xml
View file @
a893a80f
...
...
@@ -158,6 +158,11 @@
</dependency>
<dependency>
<groupId>
com.drewnoakes
</groupId>
<artifactId>
metadata-extractor
</artifactId>
<version>
2.15.0
</version>
</dependency>
<dependency>
...
...
ch-core/src/main/java/com/wwdz/ch/core/storage/StorageService.java
View file @
a893a80f
...
...
@@ -6,6 +6,11 @@ import java.io.InputStream;
import
java.nio.file.Path
;
import
java.util.stream.Stream
;
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.ExifIFD0Directory
;
import
com.wwdz.ch.core.consts.CommConsts
;
import
com.wwdz.ch.core.consts.MediaTypeEnum
;
import
com.wwdz.ch.db.dao.dts.DtsStorageDao
;
...
...
@@ -59,27 +64,37 @@ public class StorageService {
*/
public
String
store
(
InputStream
inputStream
,
long
contentLength
,
String
contentType
,
String
fileName
)
{
BufferedImage
bufferedImage
=
null
;
boolean
rotation
=
false
;
try
{
bufferedImage
=
ImageIO
.
read
(
inputStream
);
}
catch
(
IOException
e
)
{
Metadata
metadata
=
ImageMetadataReader
.
readMetadata
(
inputStream
);
Directory
imageDirectory
=
metadata
.
getFirstDirectoryOfType
(
ExifIFD0Directory
.
class
);
int
orientation
=
1
;
try
{
orientation
=
imageDirectory
.
getInt
(
ExifIFD0Directory
.
TAG_ORIENTATION
);
}
catch
(
MetadataException
ignore
)
{
}
switch
(
orientation
)
{
case
5
:
// - PI/2 and Flip X
case
6
:
// -PI/2 and -width
case
7
:
// PI/2 and Flip
case
8
:
// PI / 2
rotation
=
true
;
}
}
catch
(
Exception
e
)
{
throw
new
RuntimeException
(
e
);
}
String
type
=
MediaTypeEnum
.
getByMime
(
contentType
)
==
null
?
MediaTypeEnum
.
IMAGE_JPG
.
getExt
()
:
MediaTypeEnum
.
getByMime
(
contentType
).
getExt
();
String
keyName
=
CommConsts
.
UPLOAD_PRE_DIRECTORY
+
CommonUtils
.
getUUID
()
+
"_"
+
bufferedImage
.
getWidth
()
+
"x"
+
bufferedImage
.
getHeight
()+
"."
+
type
;
String
keyName
;
if
(
rotation
)
{
keyName
=
CommConsts
.
UPLOAD_PRE_DIRECTORY
+
CommonUtils
.
getUUID
()
+
"_"
+
bufferedImage
.
getHeight
()
+
"x"
+
bufferedImage
.
getWidth
()
+
"."
+
type
;
}
else
{
keyName
=
CommConsts
.
UPLOAD_PRE_DIRECTORY
+
CommonUtils
.
getUUID
()
+
"_"
+
bufferedImage
.
getWidth
()
+
"x"
+
bufferedImage
.
getHeight
()
+
"."
+
type
;
}
InputStream
imageStream
=
bufferedImageToInputStream
(
bufferedImage
,
type
);
storage
.
store
(
imageStream
,
contentLength
,
contentType
,
keyName
);
return
generateUrl
(
keyName
);
// String url = generateUrl(key);
// DtsStorage storageInfo = new DtsStorage();
// storageInfo.setName(fileName);
// storageInfo.setSize((int) contentLength);
// storageInfo.setType(contentType);
// storageInfo.setKey(key);
// storageInfo.setUrl(url);
// DtsStorageService.add(storageInfo);
// return url;
}
private
String
generateKey
(
String
originalFilename
)
{
...
...
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