Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
S
stable-diffusion-webui
Project
Project
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
Administrator
stable-diffusion-webui
Commits
684d7059
Unverified
Commit
684d7059
authored
Dec 24, 2022
by
AUTOMATIC1111
Committed by
GitHub
Dec 24, 2022
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #5808 from stysmmaker/patch/fix-fnt-size
Prevent overlapping in X/Y plot by changing font size
parents
55f3ef87
b7c478c3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
7 deletions
+16
-7
images.py
modules/images.py
+16
-7
No files found.
modules/images.py
View file @
684d7059
...
...
@@ -136,8 +136,19 @@ def draw_grid_annotations(im, width, height, hor_texts, ver_texts):
lines
.
append
(
word
)
return
lines
def
draw_texts
(
drawing
,
draw_x
,
draw_y
,
lines
):
def
get_font
(
fontsize
):
try
:
return
ImageFont
.
truetype
(
opts
.
font
or
Roboto
,
fontsize
)
except
Exception
:
return
ImageFont
.
truetype
(
Roboto
,
fontsize
)
def
draw_texts
(
drawing
,
draw_x
,
draw_y
,
lines
,
initial_fnt
,
initial_fontsize
):
for
i
,
line
in
enumerate
(
lines
):
fnt
=
initial_fnt
fontsize
=
initial_fontsize
while
drawing
.
multiline_textsize
(
line
.
text
,
font
=
fnt
)[
0
]
>
line
.
allowed_width
and
fontsize
>
0
:
fontsize
-=
1
fnt
=
get_font
(
fontsize
)
drawing
.
multiline_text
((
draw_x
,
draw_y
+
line
.
size
[
1
]
/
2
),
line
.
text
,
font
=
fnt
,
fill
=
color_active
if
line
.
is_active
else
color_inactive
,
anchor
=
"mm"
,
align
=
"center"
)
if
not
line
.
is_active
:
...
...
@@ -148,10 +159,7 @@ def draw_grid_annotations(im, width, height, hor_texts, ver_texts):
fontsize
=
(
width
+
height
)
//
25
line_spacing
=
fontsize
//
2
try
:
fnt
=
ImageFont
.
truetype
(
opts
.
font
or
Roboto
,
fontsize
)
except
Exception
:
fnt
=
ImageFont
.
truetype
(
Roboto
,
fontsize
)
fnt
=
get_font
(
fontsize
)
color_active
=
(
0
,
0
,
0
)
color_inactive
=
(
153
,
153
,
153
)
...
...
@@ -178,6 +186,7 @@ def draw_grid_annotations(im, width, height, hor_texts, ver_texts):
for
line
in
texts
:
bbox
=
calc_d
.
multiline_textbbox
((
0
,
0
),
line
.
text
,
font
=
fnt
)
line
.
size
=
(
bbox
[
2
]
-
bbox
[
0
],
bbox
[
3
]
-
bbox
[
1
])
line
.
allowed_width
=
allowed_width
hor_text_heights
=
[
sum
([
line
.
size
[
1
]
+
line_spacing
for
line
in
lines
])
-
line_spacing
for
lines
in
hor_texts
]
ver_text_heights
=
[
sum
([
line
.
size
[
1
]
+
line_spacing
for
line
in
lines
])
-
line_spacing
*
len
(
lines
)
for
lines
in
...
...
@@ -194,13 +203,13 @@ def draw_grid_annotations(im, width, height, hor_texts, ver_texts):
x
=
pad_left
+
width
*
col
+
width
/
2
y
=
pad_top
/
2
-
hor_text_heights
[
col
]
/
2
draw_texts
(
d
,
x
,
y
,
hor_texts
[
col
])
draw_texts
(
d
,
x
,
y
,
hor_texts
[
col
]
,
fnt
,
fontsize
)
for
row
in
range
(
rows
):
x
=
pad_left
/
2
y
=
pad_top
+
height
*
row
+
height
/
2
-
ver_text_heights
[
row
]
/
2
draw_texts
(
d
,
x
,
y
,
ver_texts
[
row
])
draw_texts
(
d
,
x
,
y
,
ver_texts
[
row
]
,
fnt
,
fontsize
)
return
result
...
...
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