Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Z
zhichan
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
蒋勇
zhichan
Commits
190a5a33
Commit
190a5a33
authored
May 14, 2020
by
高宇强
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gyq
parent
26a021d6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
153 additions
and
15 deletions
+153
-15
ailogo/CustomizeBaseLogo.py
+0
-0
ailogo/GetLogo.py
+47
-15
ailogo/LogoTemplateDownload.py
+106
-0
No files found.
ailogo/CustomizeBaseLogo.py
0 → 100644
View file @
190a5a33
This diff is collapsed.
Click to expand it.
ailogo/GetLogo.py
View file @
190a5a33
...
...
@@ -8,6 +8,7 @@
import
LogoBaseGenerator
import
pymysql
import
re
import
CustomizeBaseLogo
def
getLogoUrl
(
inputdata
):
connection
=
pymysql
.
connect
(
host
=
'rm-2zey194899z131oufao.mysql.rds.aliyuncs.com'
,
port
=
3306
,
user
=
'root'
,
...
...
@@ -26,28 +27,59 @@ def getLogoUrl(inputdata):
slogan_color
=
data
[
"sec_color"
]
log_id
=
data
[
"logo_id"
]
font_id
=
data
[
"font_id"
]
select_url
=
'select pic_url from logo_desc where id =
%
s'
%
log_id
type
=
data
[
"type"
]
model_id
=
log_id
if
log_id
>
76
and
log_id
<
83
:
model_id
=
log_id
-
76
elif
log_id
>
84
and
log_id
<
87
:
model_id
=
log_id
-
78
if
type
==
"standard"
or
(
model_id
>=
0
and
model_id
<=
8
):
select_url
=
'select pic_url from logo_desc where id =
%
s'
%
log_id
else
:
select_url
=
'select pic_url from big_template where small_id =
%
s'
%
log_id
cur
.
execute
(
select_url
)
pic
=
cur
.
fetchone
()
logo_url
=
pic
[
"pic_url"
]
select_url
=
'select name from logo_font where id =
%
s'
%
font_id
select_url
=
'select name from logo_font where id =
%
s'
%
font_id
cur
.
execute
(
select_url
)
pic1
=
cur
.
fetchone
()
imagepath
=
pic1
[
"name"
]
imagepath
=
pic1
[
"name"
]
font_url
=
'font/cn/'
+
imagepath
#font_url = 'E:\\python\\logo\\bendi\\opencvTest\\font\\cn\\' + imagepath
gen_json
=
{
'brand_text'
:
brand_text
,
# 品牌名称
'brand_color'
:
brand_color
,
# 字体颜色
'brand_location'
:
brand_location
,
# 左右上下
'slogan_text'
:
slogan_text
,
# 标语名称,可以为空
'slogan_color'
:
slogan_color
,
# 标语颜色
'logo_url'
:
logo_url
,
# 图片地址
'brand_font'
:
font_url
# 字体路径
}
if
type
==
"standard"
:
gen_json
=
{
'brand_text'
:
brand_text
,
# 品牌名称
'brand_color'
:
brand_color
,
# 字体颜色
'brand_location'
:
brand_location
,
# 左右上下
'slogan_text'
:
slogan_text
,
# 标语名称,可以为空
'slogan_color'
:
slogan_color
,
# 标语颜色
'logo_url'
:
logo_url
,
# 图片地址
'brand_font'
:
font_url
# 字体路径
}
# 生成6个图片
pic_all
=
LogoBaseGenerator
.
gen_main
(
gen_json
)
else
:
# 因目前只有八个模板,且是画的,需要把数据库的模板id对应到1-8的模板上
model_id
=
0
if
log_id
>
76
and
log_id
<
83
:
model_id
=
log_id
-
76
elif
log_id
>
84
and
log_id
<
87
:
model_id
=
log_id
-
78
gen_json
=
{
'brand_text'
:
brand_text
,
# 品牌名称
'brand_color'
:
brand_color
,
# 字体颜色
'brand_location'
:
brand_location
,
# 左右上下
"slogan_font"
:
font_url
,
'slogan_text'
:
slogan_text
,
# 标语名称,可以为空
'slogan_color'
:
slogan_color
,
# 标语颜色
'logo_url'
:
logo_url
,
# 图片地址
'brand_font'
:
font_url
,
# 字体路径
'model_id'
:
model_id
}
print
(
str
(
gen_json
))
pic_all
=
CustomizeBaseLogo
.
down_customize_logo
(
gen_json
)
#生成6个图片
pic_all
=
LogoBaseGenerator
.
gen_main
(
gen_json
)
if
pic_all
[
"status"
]
==
1
:
#更新数据库
...
...
ailogo/LogoTemplateDownload.py
0 → 100644
View file @
190a5a33
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020-05-13 8:47
# @Author : zhangyunfei
# @File : LogoTemplateDownload.py
# @Software: PyCharm
import
os
,
random
,
time
,
oss2
from
PIL
import
Image
,
ImageDraw
,
ImageFont
from
LogoUtil
import
put2oss
,
add_watermark
,
alpha2white
,
downlogo_path
,
downlogo
class
tenplateGenerator
():
def
__init__
(
self
):
self
.
width
=
1900
self
.
height
=
1400
# 品牌语和标语生成函数,该函数是品牌语和标语都存在的情况下使用
def
generator
(
self
,
model
,
brand_text
,
brand_font
,
brand_color
,
location
,
slogan_text
,
slogan_font
,
slogan_color
,
logo_img
,
bg_color
):
# 生成空白logo图像,指定背景颜色和大小
logo_gen_image
=
Image
.
new
(
model
,
(
self
.
width
,
self
.
height
),
bg_color
)
# logo_gen_image = Image.open("data/alpha.png")
# 定义画笔
draw
=
ImageDraw
.
Draw
(
logo_img
)
# 获取品牌语font的大小
brand_width
,
brand_height
=
brand_font
.
getsize
(
brand_text
)
# print('品牌语字体大小:', brand_width, brand_height)
# 获取标语font的大小
slogan_width
,
slogan_height
=
slogan_font
.
getsize
(
slogan_text
)
# print('标语字体大小:', slogan_width, slogan_height)
# 空白区域的大小为
location_width
=
location
[
2
]
-
location
[
0
]
location_height
=
location
[
3
]
-
location
[
1
]
# 中心点坐标
center_x
=
int
((
location
[
0
]
+
location
[
2
])
/
2
)
center_y
=
int
((
location
[
1
]
+
location
[
3
])
/
2
)
# 生成文字的总长度和宽度为
text_width
=
max
(
brand_width
,
slogan_width
)
text_height
=
brand_height
+
slogan_height
# print('location----------:', location_width, location_height)
# print('text------------:', text_width, text_height)
if
text_width
<
location_width
and
text_height
<
location_height
:
brand_x
=
center_x
-
int
(
brand_width
/
2
)
brand_y
=
center_y
-
int
((
brand_height
+
slogan_height
)
/
2
)
# print('品牌语开始位置:', brand_x, brand_y)
slogan_x
=
center_x
-
int
(
slogan_width
/
2
)
slogan_y
=
brand_y
+
brand_height
# print('标语开始位置:', slogan_x, slogan_y)
draw
.
text
((
brand_x
,
brand_y
),
brand_text
,
brand_color
,
brand_font
)
draw
.
text
((
slogan_x
,
slogan_y
),
slogan_text
,
slogan_color
,
slogan_font
)
scale_width
,
scale_height
=
logo_img
.
size
# logo_img_resize = logo_img.resize((scale_width ,scale_height),Image.ANTIALIAS)
# logo_gen_image.paste(logo_img, (0, 0))
logo_gen_image
.
paste
(
logo_img
,
(
950
-
int
(
scale_width
/
2
),
700
-
int
(
scale_height
/
2
)))
return
logo_gen_image
else
:
return
None
def
generator_alpha
(
self
,
brand_text
,
brand_font
,
brand_color
,
location
,
slogan_text
,
slogan_font
,
slogan_color
,
logo_img
):
# 生成空白logo图像,指定背景颜色和大小
logo_gen_image
=
Image
.
new
(
'RGBA'
,
(
self
.
width
,
self
.
height
),
(
0
,
0
,
0
,
0
))
# logo_gen_image = Image.open("data/alpha.png")
# 定义画笔
draw
=
ImageDraw
.
Draw
(
logo_img
)
# 获取品牌语font的大小
brand_width
,
brand_height
=
brand_font
.
getsize
(
brand_text
)
# print('品牌语字体大小:', brand_width, brand_height)
# 获取标语font的大小
slogan_width
,
slogan_height
=
slogan_font
.
getsize
(
slogan_text
)
# print('标语字体大小:', slogan_width, slogan_height)
# 空白区域的大小为
location_width
=
location
[
2
]
-
location
[
0
]
location_height
=
location
[
3
]
-
location
[
1
]
# 中心点坐标
center_x
=
int
((
location
[
0
]
+
location
[
2
])
/
2
)
center_y
=
int
((
location
[
1
]
+
location
[
3
])
/
2
)
# 生成文字的总长度和宽度为
text_width
=
max
(
brand_width
,
slogan_width
)
text_height
=
brand_height
+
slogan_height
# print('location----------:', location_width, location_height)
# print('text------------:', text_width, text_height)
if
text_width
<
location_width
and
text_height
<
location_height
:
brand_x
=
center_x
-
int
(
brand_width
/
2
)
brand_y
=
center_y
-
int
((
brand_height
+
slogan_height
)
/
2
)
# print('品牌语开始位置:', brand_x, brand_y)
slogan_x
=
center_x
-
int
(
slogan_width
/
2
)
slogan_y
=
brand_y
+
brand_height
# print('标语开始位置:', slogan_x, slogan_y)
draw
.
text
((
brand_x
,
brand_y
),
brand_text
,
brand_color
,
brand_font
)
draw
.
text
((
slogan_x
,
slogan_y
),
slogan_text
,
slogan_color
,
slogan_font
)
scale_width
,
scale_height
=
logo_img
.
size
# logo_img_resize = logo_img.resize((scale_width ,scale_height),Image.ANTIALIAS)
# logo_gen_image.paste(logo_img, (0, 0))
logo_gen_image
.
paste
(
logo_img
,
(
950
-
int
(
scale_width
/
2
),
700
-
int
(
scale_height
/
2
)))
return
logo_gen_image
else
:
return
None
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