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
1d64976d
Commit
1d64976d
authored
Oct 10, 2022
by
Justin Maier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify crop logic
parent
6435691b
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
13 deletions
+5
-13
extras.py
modules/extras.py
+3
-11
ui.py
modules/ui.py
+2
-2
No files found.
modules/extras.py
View file @
1d64976d
...
@@ -73,16 +73,6 @@ def run_extras(extras_mode, resize_mode, image, image_folder, gfpgan_visibility,
...
@@ -73,16 +73,6 @@ def run_extras(extras_mode, resize_mode, image, image_folder, gfpgan_visibility,
crop_info
=
" (crop)"
if
upscaling_crop
else
""
crop_info
=
" (crop)"
if
upscaling_crop
else
""
info
+=
f
"Resize to: {upscaling_resize_w:g}x{upscaling_resize_h:g}{crop_info}
\n
"
info
+=
f
"Resize to: {upscaling_resize_w:g}x{upscaling_resize_h:g}{crop_info}
\n
"
def
crop_upscaled_center
(
image
,
resize_w
,
resize_h
):
left
=
int
(
math
.
ceil
((
image
.
width
-
resize_w
)
/
2
))
right
=
image
.
width
-
int
(
math
.
floor
((
image
.
width
-
resize_w
)
/
2
))
top
=
int
(
math
.
ceil
((
image
.
height
-
resize_h
)
/
2
))
bottom
=
image
.
height
-
int
(
math
.
floor
((
image
.
height
-
resize_h
)
/
2
))
image
=
image
.
crop
((
left
,
top
,
right
,
bottom
))
return
image
if
upscaling_resize
!=
1.0
:
if
upscaling_resize
!=
1.0
:
def
upscale
(
image
,
scaler_index
,
resize
,
mode
,
resize_w
,
resize_h
,
crop
):
def
upscale
(
image
,
scaler_index
,
resize
,
mode
,
resize_w
,
resize_h
,
crop
):
small
=
image
.
crop
((
image
.
width
//
2
,
image
.
height
//
2
,
image
.
width
//
2
+
10
,
image
.
height
//
2
+
10
))
small
=
image
.
crop
((
image
.
width
//
2
,
image
.
height
//
2
,
image
.
width
//
2
+
10
,
image
.
height
//
2
+
10
))
...
@@ -94,7 +84,9 @@ def run_extras(extras_mode, resize_mode, image, image_folder, gfpgan_visibility,
...
@@ -94,7 +84,9 @@ def run_extras(extras_mode, resize_mode, image, image_folder, gfpgan_visibility,
upscaler
=
shared
.
sd_upscalers
[
scaler_index
]
upscaler
=
shared
.
sd_upscalers
[
scaler_index
]
c
=
upscaler
.
scaler
.
upscale
(
image
,
resize
,
upscaler
.
data_path
)
c
=
upscaler
.
scaler
.
upscale
(
image
,
resize
,
upscaler
.
data_path
)
if
mode
==
1
and
crop
:
if
mode
==
1
and
crop
:
c
=
crop_upscaled_center
(
c
,
resize_w
,
resize_h
)
cropped
=
Image
.
new
(
"RGB"
,
(
resize_w
,
resize_h
))
cropped
.
paste
(
c
,
box
=
(
resize_w
//
2
-
c
.
width
//
2
,
resize_h
//
2
-
c
.
height
//
2
))
c
=
cropped
cached_images
[
key
]
=
c
cached_images
[
key
]
=
c
return
c
return
c
...
...
modules/ui.py
View file @
1d64976d
...
@@ -909,8 +909,8 @@ def create_ui(wrap_gradio_gpu_call):
...
@@ -909,8 +909,8 @@ def create_ui(wrap_gradio_gpu_call):
with
gr
.
TabItem
(
'Scale to'
):
with
gr
.
TabItem
(
'Scale to'
):
with
gr
.
Group
():
with
gr
.
Group
():
with
gr
.
Row
():
with
gr
.
Row
():
upscaling_resize_w
=
gr
.
Number
(
label
=
"Width"
,
value
=
512
)
upscaling_resize_w
=
gr
.
Number
(
label
=
"Width"
,
value
=
512
,
precision
=
0
)
upscaling_resize_h
=
gr
.
Number
(
label
=
"Height"
,
value
=
512
)
upscaling_resize_h
=
gr
.
Number
(
label
=
"Height"
,
value
=
512
,
precision
=
0
)
upscaling_crop
=
gr
.
Checkbox
(
label
=
'Crop to fit'
,
value
=
True
)
upscaling_crop
=
gr
.
Checkbox
(
label
=
'Crop to fit'
,
value
=
True
)
with
gr
.
Group
():
with
gr
.
Group
():
...
...
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