Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
haoban-manage3.0
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
haoban3.0
haoban-manage3.0
Commits
e9fceca0
Commit
e9fceca0
authored
Apr 26, 2023
by
songyinghui
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 新版图片合成
parent
f445e3c8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
17 deletions
+50
-17
pom.xml
haoban-manage3-service/pom.xml
+5
-0
DrawImageUtils.java
...va/com/gic/haoban/manage/service/util/DrawImageUtils.java
+45
-17
No files found.
haoban-manage3-service/pom.xml
View file @
e9fceca0
...
...
@@ -196,6 +196,11 @@
<artifactId>
gic-order-api
</artifactId>
<version>
${gic-order-api}
</version>
</dependency>
<dependency>
<groupId>
com.freewayso
</groupId>
<artifactId>
image-combiner
</artifactId>
<version>
2.6.3
</version>
</dependency>
</dependencies>
<build>
...
...
haoban-manage3-service/src/main/java/com/gic/haoban/manage/service/util/DrawImageUtils.java
View file @
e9fceca0
package
com
.
gic
.
haoban
.
manage
.
service
.
util
;
import
com.alibaba.fastjson.JSON
;
import
com.freewayso.image.combiner.ImageCombiner
;
import
com.freewayso.image.combiner.enums.OutputFormat
;
import
com.freewayso.image.combiner.enums.ZoomMode
;
import
com.gic.thirdparty.cloudfile.CloudFileUtil
;
import
com.gic.thirdparty.cloudfile.enums.CloudFileBusinessOptEnum
;
import
com.gic.thirdparty.cloudfile.enums.CloudFileTypeEnum
;
...
...
@@ -104,17 +107,6 @@ public class DrawImageUtils {
return
null
;
}
static
InputStream
inputStream
=
null
;
static
{
try
{
URL
url
=
new
URL
(
"https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-80819999f96f448d9fcccb5ac86e6c37.png"
);
inputStream
=
url
.
openStream
();
}
catch
(
Exception
ex
)
{
}
}
/***
* 二维码合成
...
...
@@ -185,6 +177,46 @@ public class DrawImageUtils {
return
url
;
}
public
static
String
addWaterNew
(
String
factoryCode
,
String
url
,
String
qrCodeUrl
)
{
// 读取原图片信息
//文件转化为图片
try
{
long
startTime
=
System
.
currentTimeMillis
();
ImageCombiner
imageCombiner
=
new
ImageCombiner
(
url
,
OutputFormat
.
JPG
);
BufferedImage
combinedImage
=
imageCombiner
.
getCombinedImage
();
int
srcImgWidth
=
combinedImage
.
getWidth
(
null
);
int
srcImgHeight
=
combinedImage
.
getHeight
(
null
);
log
.
info
(
"图片宽度:{}, 图片高度:{}"
,
srcImgHeight
,
srcImgHeight
);
if
(
srcImgHeight
>
2000
)
{
log
.
info
(
"原图片高度超过2000 高度:{}, 等比压缩"
,
srcImgHeight
);
// 按高度等比压缩
int
tempWidth
=
BigDecimal
.
valueOf
(
srcImgWidth
)
.
multiply
(
BigDecimal
.
valueOf
(
2000
).
divide
(
BigDecimal
.
valueOf
(
srcImgHeight
),
2
,
RoundingMode
.
HALF_DOWN
))
.
intValue
();
log
.
info
(
"压缩后的宽:{}"
,
tempWidth
);
srcImgHeight
=
2000
;
srcImgWidth
=
tempWidth
;
imageCombiner
=
new
ImageCombiner
(
combinedImage
,
tempWidth
,
2000
,
ZoomMode
.
Height
,
OutputFormat
.
JPG
);
}
// 计算二维码宽度
int
qrCodeWidthTemp
=
srcImgWidth
*
136
/
750
;
imageCombiner
.
addImageElement
(
qrCodeUrl
,
srcImgWidth
-
(
qrCodeWidthTemp
+
20
),
srcImgHeight
-
(
qrCodeWidthTemp
+
20
),
qrCodeWidthTemp
,
qrCodeWidthTemp
,
ZoomMode
.
Height
);
imageCombiner
.
combine
();
InputStream
combinedImageStream
=
imageCombiner
.
getCombinedImageStream
();
log
.
info
(
"合成之后的大小 {}"
,
combinedImageStream
.
available
());
CloudFileInfo
cloudFileInfo
=
CloudFileUtil
.
uploadFile
(
combinedImageStream
,
"jpg"
,
CloudFileTypeEnum
.
IMAGE
,
factoryCode
,
CloudFileBusinessOptEnum
.
HAOBAN_COMMON
);
log
.
info
(
"上传图片结果:{}"
,
JSON
.
toJSONString
(
cloudFileInfo
));
long
endTime
=
System
.
currentTimeMillis
();
log
.
info
(
"合成图片耗时 {} 秒"
,
(
endTime
-
startTime
)
/
1000
);
if
(
cloudFileInfo
!=
null
)
{
return
cloudFileInfo
.
getOrgFileUrl
();
}
}
catch
(
Exception
ex
)
{
log
.
info
(
"处理图片发生异常"
,
ex
);
}
return
url
;
}
public
static
BufferedImage
resize
(
Image
img
,
int
h
,
int
w
,
boolean
clip
)
throws
IOException
{
//参数是TYPE_3BYTE_BGR时,图片最清晰!
BufferedImage
image
=
new
BufferedImage
(
w
,
h
,
BufferedImage
.
TYPE_4BYTE_ABGR
);
...
...
@@ -204,16 +236,12 @@ public class DrawImageUtils {
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
try
{
URL
url
=
new
URL
(
"https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-80819999f96f448d9fcccb5ac86e6c37.png"
);
inputStream
=
url
.
openStream
();
}
catch
(
Exception
ex
)
{
}
String
qrcodeUrl
=
"https://gicinner-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-80819999f96f448d9fcccb5ac86e6c37.png"
;
String
url
=
"https://jhdm-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-7c3bc8061ffb4e2694c0e288a1ce176b.jpeg?imageView2/format/jpg/q/50"
;
//String url = "https://newdmwltest-1251519181.cos.ap-shanghai.myqcloud.com/image/material_content-bd89447576b5438d8045def2da2c4c0f.jpg?imageView2/format/jpg/q/50";
System
.
setProperty
(
"gic.module.name"
,
"haoban-manage3-service"
);
DrawImageUtils
.
addWater
(
"jhdm"
,
url
,
inputStream
);
System
.
out
.
println
(
DrawImageUtils
.
addWaterNew
(
"jhdm"
,
url
,
qrcodeUrl
)
);
// Random random = new Random();
// String url = DrawImageUtils.drawImage("jhdm", Math.abs(random.nextInt(1000)) + "",
// Math.abs(random.nextInt(1000)) + "万", DrawBkgImg.AREA_MONTH_BKG);
...
...
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