Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
midjourney-proxy
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
徐少华
midjourney-proxy
Commits
e0615d22
Commit
e0615d22
authored
Oct 28, 2018
by
songxiang
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of
http://192.168.89.173/rays/pcloud-common-parent.git
parents
15de15c5
878d6ff9
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
117 additions
and
47 deletions
+117
-47
ProductTypeConstant.java
.../com/pcloud/common/core/constant/ProductTypeConstant.java
+16
-1
pom.xml
pcloud-common/pom.xml
+6
-0
HttpKit.java
...common/src/main/java/com/pcloud/common/utils/HttpKit.java
+56
-0
PictureUtil.java
...on/src/main/java/com/pcloud/common/utils/PictureUtil.java
+39
-46
No files found.
pcloud-common-core/src/main/java/com/pcloud/common/core/constant/ProductTypeConstant.java
View file @
e0615d22
...
@@ -208,6 +208,21 @@ public class ProductTypeConstant {
...
@@ -208,6 +208,21 @@ public class ProductTypeConstant {
public
static
final
String
PRETESTAPP
=
"PRETESTAPP"
;
public
static
final
String
PRETESTAPP
=
"PRETESTAPP"
;
/**
/**
* 音频
*/
public
static
final
String
AUDIO_RESOURCE
=
"AUDIO_RESOURCE"
;
/**
* 问答
*/
public
static
final
String
QA_APP
=
"QA_APP"
;
/**
* 电子书
*/
public
static
final
String
EBOOK_APP
=
"EBOOK_APP"
;
/**
* 热门作品类型
* 热门作品类型
*/
*/
public
static
final
String
[]
HOT_PRODUCT_TYPE
=
{
QA
,
PDF
,
VIDEO
,
PRETEST
};
public
static
final
String
[]
HOT_PRODUCT_TYPE
=
{
QA
,
PDF
,
VIDEO
,
PRETEST
};
...
@@ -233,7 +248,7 @@ public class ProductTypeConstant {
...
@@ -233,7 +248,7 @@ public class ProductTypeConstant {
* 应用型作品(伴随应用使用)
* 应用型作品(伴随应用使用)
*/
*/
public
static
final
String
[]
APP_PRODUCT
=
{
LOOK
,
LIVE
,
TUTOR
,
GROUP
,
ZSCORE
,
VOTE
,
CLOCK
,
TEST
,
AUDIOAPP
,
ANSWER
,
public
static
final
String
[]
APP_PRODUCT
=
{
LOOK
,
LIVE
,
TUTOR
,
GROUP
,
ZSCORE
,
VOTE
,
CLOCK
,
TEST
,
AUDIOAPP
,
ANSWER
,
EF
,
MUSIC
,
VIDEO_COURSE
,
PRETESTAPP
};
EF
,
MUSIC
,
VIDEO_COURSE
,
PRETESTAPP
,
AUDIO_RESOURCE
,
QA_APP
,
EBOOK_APP
};
/**
/**
* 数据平台埋点型作品
* 数据平台埋点型作品
...
...
pcloud-common/pom.xml
View file @
e0615d22
...
@@ -70,6 +70,12 @@
...
@@ -70,6 +70,12 @@
<version>
1.0.0-rc.2
</version>
<version>
1.0.0-rc.2
</version>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
com.squareup.okhttp3
</groupId>
<artifactId>
okhttp
</artifactId>
<version>
3.2.0
</version>
</dependency>
<dependency>
<groupId>
io.micrometer
</groupId>
<groupId>
io.micrometer
</groupId>
<artifactId>
micrometer-registry-influx
</artifactId>
<artifactId>
micrometer-registry-influx
</artifactId>
<version>
1.0.0-rc.2
</version>
<version>
1.0.0-rc.2
</version>
...
...
pcloud-common/src/main/java/com/pcloud/common/utils/HttpKit.java
0 → 100644
View file @
e0615d22
package
com
.
pcloud
.
common
.
utils
;
import
okhttp3.MediaType
;
import
okhttp3.OkHttpClient
;
import
okhttp3.Request
;
import
okhttp3.Response
;
import
java.io.IOException
;
import
java.util.concurrent.TimeUnit
;
public
final
class
HttpKit
{
private
HttpKit
()
{
}
private
static
OkHttpClient
httpClient
=
new
OkHttpClient
().
newBuilder
()
.
connectTimeout
(
10
,
TimeUnit
.
SECONDS
)
.
writeTimeout
(
10
,
TimeUnit
.
SECONDS
)
.
readTimeout
(
30
,
TimeUnit
.
SECONDS
).
build
();
private
static
final
MediaType
CONTENT_TYPE_FORM
=
MediaType
.
parse
(
"application/json"
);
protected
static
String
post
(
String
url
,
String
data
)
{
okhttp3
.
RequestBody
body
=
okhttp3
.
RequestBody
.
create
(
CONTENT_TYPE_FORM
,
data
);
okhttp3
.
Request
request
=
new
okhttp3
.
Request
.
Builder
().
url
(
url
)
.
post
(
body
).
build
();
return
exec
(
request
);
}
public
static
String
get
(
String
url
)
throws
IOException
{
Request
request
=
new
Request
.
Builder
()
.
url
(
url
).
addHeader
(
"token"
,
"0Id4baiRH818SVJjC2qjhdMwQh5DSfCJ"
)
.
build
();
Response
response
=
httpClient
.
newCall
(
request
).
execute
();
return
response
.
body
().
string
();
// 返回的是string 类型
}
private
static
String
exec
(
Request
request
)
{
try
{
Response
response
=
httpClient
.
newCall
(
request
)
.
execute
();
if
(!
response
.
isSuccessful
())
throw
new
RuntimeException
(
"Unexpected code "
+
response
);
return
response
.
body
().
string
();
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
}
pcloud-common/src/main/java/com/pcloud/common/utils/PictureUtil.java
View file @
e0615d22
...
@@ -2,9 +2,12 @@ package com.pcloud.common.utils;/**
...
@@ -2,9 +2,12 @@ package com.pcloud.common.utils;/**
* Created by ${user} on ${date}
* Created by ${user} on ${date}
*/
*/
import
com.alibaba.fastjson.JSON
;
import
com.pcloud.common.entity.UploadResultInfo
;
import
com.pcloud.common.entity.UploadResultInfo
;
import
com.pcloud.common.enums.ImageTypeEnum
;
import
com.pcloud.common.enums.ImageTypeEnum
;
import
com.pcloud.common.utils.aliyun.OssUtils
;
import
com.pcloud.common.utils.aliyun.OssUtils
;
import
com.pcloud.common.utils.httpclient.SimpleHttpUtils
;
import
com.pcloud.common.utils.json.JSONUtils
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
...
@@ -77,6 +80,14 @@ public class PictureUtil {
...
@@ -77,6 +80,14 @@ public class PictureUtil {
return
builder
.
toString
().
toUpperCase
();
return
builder
.
toString
().
toUpperCase
();
}
}
private
static
BufferedImage
subPicByWhite
(
BufferedImage
picImage
){
return
picImage
.
getSubimage
(
9
,
9
,
699
,
300
);
}
public
static
Color
toColorFromString
(
String
colorStr
){
colorStr
=
colorStr
.
substring
(
2
);
Color
color
=
new
Color
(
Integer
.
parseInt
(
colorStr
,
16
))
;
return
color
;
}
private
static
BufferedImage
subPic
(
BufferedImage
picImage
){
private
static
BufferedImage
subPic
(
BufferedImage
picImage
){
int
w
=
picImage
.
getWidth
();
int
w
=
picImage
.
getWidth
();
...
@@ -101,54 +112,36 @@ public class PictureUtil {
...
@@ -101,54 +112,36 @@ public class PictureUtil {
public
static
String
getQrCover
(
String
bookPic
,
boolean
isDefault
){
public
static
String
getQrCover
(
String
bookPic
,
boolean
isDefault
){
String
resultPath
=
""
;
String
resultPath
=
""
;
try
{
try
{
int
backWidth
=
702
;
Color
color
;
int
backHeight
=
299
;
if
(
bookPic
.
contains
(
"/oss/"
)){
int
splitPoint
=
196
;
String
s
=
SimpleHttpUtils
.
httpGet
(
bookPic
+
"?x-oss-process=image/average-hue"
,
null
);
int
bookWidth
=
157
;
System
.
out
.
println
(
s
);
int
bookHeight
=
224
;
Map
map
=
JSONUtils
.
jsonToMap
(
s
,
String
.
class
,
String
.
class
);
int
borderWidth
=
185
;
String
rgb
=
(
String
)
map
.
get
(
"RGB"
);
int
borderHeight
=
252
;
color
=
toColorFromString
(
rgb
);
int
playButtonSize
=
80
;
}
else
{
//取书封面和播放按钮图
color
=
getImagePixel
(
bookPic
);
BufferedImage
bookPicImage
;
BufferedImage
playPicImage
;
BufferedImage
defaultBackgroundImage
;
bookPicImage
=
ImageIO
.
read
(
new
URL
(
bookPic
));
if
(
bookPicImage
.
getWidth
()*
bookPicImage
.
getHeight
()>
10000
)
{
BufferedImage
pic1
=
new
BufferedImage
(
bookWidth
,
bookHeight
,
BufferedImage
.
TYPE_3BYTE_BGR
);
Graphics2D
g11
=
pic1
.
createGraphics
();
g11
.
drawImage
(
bookPicImage
.
getScaledInstance
(
bookWidth
,
bookHeight
,
Image
.
SCALE_SMOOTH
),
0
,
0
,
null
);
g11
.
dispose
();
bookPicImage
=
pic1
;
}
bookPicImage
=
subPic
(
bookPicImage
);
playPicImage
=
ImageIO
.
read
(
new
URL
(
playPic
));
defaultBackgroundImage
=
ImageIO
.
read
(
new
URL
(
defaultBackgroundPic
));
//画一个空的背景
BufferedImage
bg
=
new
BufferedImage
(
backWidth
,
backHeight
,
BufferedImage
.
TYPE_3BYTE_BGR
);
Graphics2D
g
=
bg
.
createGraphics
();
//获取主题色
Color
c
=
getImagePixel
(
bookPic
);
//画纯色的背景或者默认背景图
g
.
setColor
(
c
);
if
(
isDefault
){
g
.
drawImage
(
defaultBackgroundImage
.
getScaledInstance
(
backWidth
,
splitPoint
,
Image
.
SCALE_DEFAULT
),
0
,
0
,
null
);
}
else
{
g
.
fillRect
(
0
,
0
,
backWidth
,
splitPoint
);
}
}
g
.
setColor
(
defaultColor
);
String
lightIcon
=
"https://oss.5rs.me/oss/uploadfe/png/12dcbc38528d926912c444765d786a9a.png"
;
g
.
fillRect
(
0
,
splitPoint
,
backWidth
,
backHeight
-
splitPoint
);
String
deepIcon
=
"https://oss.5rs.me/oss/uploadfe/png/60612a7415bdac8533568ae0c21a94b6.png"
;
//插入书籍图和播放按钮
String
icon
;
g
.
drawImage
(
bookPicImage
.
getScaledInstance
(
bookWidth
,
bookHeight
,
Image
.
SCALE_SMOOTH
),
(
backWidth
-
bookWidth
)/
2
,
(
backHeight
-
bookHeight
)/
2
,
null
);
if
(
color
!=
null
&&
(
color
.
getRed
()<
180
||
color
.
getBlue
()<
180
||
color
.
getGreen
()<
180
)){
g
.
drawImage
(
playPicImage
.
getScaledInstance
(
playButtonSize
,
playButtonSize
,
Image
.
SCALE_DEFAULT
),
(
backWidth
-
playButtonSize
)/
2
,
(
backHeight
-
playButtonSize
)/
2
,
null
);
icon
=
lightIcon
;
//画边框
}
else
{
g
.
setColor
(
borderColor
);
icon
=
deepIcon
;
g
.
drawRect
((
backWidth
-
bookWidth
)/
2
,
(
backHeight
-
bookHeight
)/
2
,
bookWidth
,
bookHeight
);
}
// 保存并上传图片
String
html
=
"<div style = \"position: relative;width: 700px;height: 300px;border: 0px solid green;background-color: #fcfcfc;text-align: center;\"> <div style = \"position: absolute;width: 100%;height: 66%;background-color: rgb("
+
color
.
getRed
()+
","
+
color
.
getGreen
()+
","
+
color
.
getBlue
()+
");overflow: hidden;\"> <div style = \"position: absolute;top: 20px;right: -20px;background-image: url('"
+
icon
+
"');background-size: 100%;width: 219px;height: 149px;\"> </div> </div><div style=\"position: relative;display: inline-block;width: 158px;height: 225px;box-shadow: 0px 4px 14px 2px rgba(14, 47, 70, 0.2);border-radius: 4px;border: solid 1px #ddd; margin-top: 35px;background: url('"
+
bookPic
+
"') no-repeat;background-size: cover;background-position: center;\"></div></div>"
;
Map
<
String
,
String
>
header
=
new
HashMap
<>();
header
.
put
(
"Content-Type"
,
"application/json"
);
Map
<
String
,
String
>
param
=
new
HashMap
<>();
param
.
put
(
"htmlCode"
,
html
);
String
postResult
=
HttpKit
.
post
(
"http://192.168.92.111:8214/transcode/htm2img/jpg"
,
JSON
.
toJSONString
(
param
));
Map
map
=
JSONUtils
.
jsonToMap
(
postResult
,
String
.
class
,
String
.
class
);
String
pic
=
(
String
)
map
.
get
(
"data"
);
BufferedImage
bookPicImage
=
ImageIO
.
read
(
new
URL
(
pic
));
BufferedImage
bufferedImage
=
subPicByWhite
(
bookPicImage
);
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
ByteArrayOutputStream
os
=
new
ByteArrayOutputStream
();
ImageIO
.
write
(
b
g
,
ImageTypeEnum
.
JPG
.
value
,
os
);
ImageIO
.
write
(
b
ufferedImage
,
ImageTypeEnum
.
JPG
.
value
,
os
);
UploadResultInfo
uploadResultInfo
=
OssUtils
.
uploadFileByte
(
os
.
toByteArray
(),
UUIDUitl
.
taskName
(),
ImageTypeEnum
.
JPG
.
value
);
UploadResultInfo
uploadResultInfo
=
OssUtils
.
uploadFileByte
(
os
.
toByteArray
(),
UUIDUitl
.
taskName
(),
ImageTypeEnum
.
JPG
.
value
);
os
.
close
();
os
.
close
();
resultPath
=
uploadResultInfo
==
null
?
null
:
uploadResultInfo
.
getUrl
();
resultPath
=
uploadResultInfo
==
null
?
null
:
uploadResultInfo
.
getUrl
();
...
...
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