Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
S
Stable Diffusion Webui
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
novelai-storage
Stable Diffusion Webui
Commits
df7070ec
Commit
df7070ec
authored
May 11, 2023
by
Aarni Koskela
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deduplicate get_font code
parent
16e4d791
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
13 deletions
+9
-13
modules/images.py
modules/images.py
+7
-6
modules/textual_inversion/image_embedding.py
modules/textual_inversion/image_embedding.py
+2
-7
No files found.
modules/images.py
View file @
df7070ec
...
@@ -24,6 +24,13 @@ from modules.shared import opts
...
@@ -24,6 +24,13 @@ from modules.shared import opts
LANCZOS
=
(
Image
.
Resampling
.
LANCZOS
if
hasattr
(
Image
,
'Resampling'
)
else
Image
.
LANCZOS
)
LANCZOS
=
(
Image
.
Resampling
.
LANCZOS
if
hasattr
(
Image
,
'Resampling'
)
else
Image
.
LANCZOS
)
def
get_font
(
fontsize
:
int
):
try
:
return
ImageFont
.
truetype
(
opts
.
font
or
Roboto
,
fontsize
)
except
Exception
:
return
ImageFont
.
truetype
(
Roboto
,
fontsize
)
def
image_grid
(
imgs
,
batch_size
=
1
,
rows
=
None
):
def
image_grid
(
imgs
,
batch_size
=
1
,
rows
=
None
):
if
rows
is
None
:
if
rows
is
None
:
if
opts
.
n_rows
>
0
:
if
opts
.
n_rows
>
0
:
...
@@ -142,12 +149,6 @@ def draw_grid_annotations(im, width, height, hor_texts, ver_texts, margin=0):
...
@@ -142,12 +149,6 @@ def draw_grid_annotations(im, width, height, hor_texts, ver_texts, margin=0):
lines
.
append
(
word
)
lines
.
append
(
word
)
return
lines
return
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
):
def
draw_texts
(
drawing
,
draw_x
,
draw_y
,
lines
,
initial_fnt
,
initial_fontsize
):
for
line
in
lines
:
for
line
in
lines
:
fnt
=
initial_fnt
fnt
=
initial_fnt
...
...
modules/textual_inversion/image_embedding.py
View file @
df7070ec
...
@@ -3,9 +3,7 @@ import json
...
@@ -3,9 +3,7 @@ import json
import
numpy
as
np
import
numpy
as
np
import
zlib
import
zlib
from
PIL
import
Image
,
ImageDraw
,
ImageFont
from
PIL
import
Image
,
ImageDraw
,
ImageFont
from
fonts.ttf
import
Roboto
import
torch
import
torch
from
modules.shared
import
opts
class
EmbeddingEncoder
(
json
.
JSONEncoder
):
class
EmbeddingEncoder
(
json
.
JSONEncoder
):
...
@@ -136,11 +134,8 @@ def caption_image_overlay(srcimage, title, footerLeft, footerMid, footerRight, t
...
@@ -136,11 +134,8 @@ def caption_image_overlay(srcimage, title, footerLeft, footerMid, footerRight, t
image
=
srcimage
.
copy
()
image
=
srcimage
.
copy
()
fontsize
=
32
fontsize
=
32
if
textfont
is
None
:
if
textfont
is
None
:
try
:
from
modules.images
import
get_font
textfont
=
ImageFont
.
truetype
(
opts
.
font
or
Roboto
,
fontsize
)
textfont
=
get_font
(
fontsize
)
textfont
=
opts
.
font
or
Roboto
except
Exception
:
textfont
=
Roboto
factor
=
1.5
factor
=
1.5
gradient
=
Image
.
new
(
'RGBA'
,
(
1
,
image
.
size
[
1
]),
color
=
(
0
,
0
,
0
,
0
))
gradient
=
Image
.
new
(
'RGBA'
,
(
1
,
image
.
size
[
1
]),
color
=
(
0
,
0
,
0
,
0
))
...
...
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