Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lib_base
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
sikang
lib_base
Commits
6f825567
Commit
6f825567
authored
Apr 12, 2019
by
sikang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
udpate script
parent
989c4c69
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
3 deletions
+7
-3
script/image_mark.py
+7
-3
No files found.
script/image_mark.py
View file @
6f825567
...
...
@@ -4,18 +4,22 @@ import sys
import
random
from
PIL
import
Image
,
ImageDraw
,
ImageFont
def
add_text_to_image
(
image
,
text
):
mode
=
'RGB'
if
image
.
endswith
(
".png"
):
mode
=
"RGBA"
#水印字体随机大小
font_size
=
random
.
randint
(
30
,
60
)
font
=
ImageFont
.
truetype
(
'Arial.ttf'
,
font_size
)
# 添加背景
new_img
=
Image
.
new
(
'RGBA'
,
(
image
.
size
[
0
]
*
3
,
image
.
size
[
1
]
*
3
),
(
0
,
0
,
0
,
0
))
new_img
=
Image
.
new
(
mode
,
(
image
.
size
[
0
]
*
3
,
image
.
size
[
1
]
*
3
),
(
0
,
0
,
0
,
0
))
new_img
.
paste
(
image
,
image
.
size
)
# 添加水印
font_len
=
len
(
text
)
rgba_image
=
new_img
.
convert
(
'RGBA'
)
text_overlay
=
Image
.
new
(
'RGBA'
,
rgba_image
.
size
,
(
255
,
255
,
255
,
0
))
rgba_image
=
new_img
.
convert
(
mode
)
text_overlay
=
Image
.
new
(
mode
,
rgba_image
.
size
,
(
255
,
255
,
255
,
0
))
image_draw
=
ImageDraw
.
Draw
(
text_overlay
)
#随机位置
...
...
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