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
1be5933b
Unverified
Commit
1be5933b
authored
Oct 23, 2022
by
captin411
Committed by
GitHub
Oct 23, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto cropping now works with non square crops
parent
0ddaf8d2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
269 additions
and
240 deletions
+269
-240
autocrop.py
modules/textual_inversion/autocrop.py
+269
-240
No files found.
modules/textual_inversion/autocrop.py
View file @
1be5933b
...
@@ -11,14 +11,31 @@ RED = "#F00"
...
@@ -11,14 +11,31 @@ RED = "#F00"
def
crop_image
(
im
,
settings
):
def
crop_image
(
im
,
settings
):
""" Intelligently crop an image to the subject matter """
""" Intelligently crop an image to the subject matter """
if
im
.
height
>
im
.
width
:
im
=
im
.
resize
((
settings
.
crop_width
,
settings
.
crop_height
*
im
.
height
//
im
.
width
))
elif
im
.
width
>
im
.
height
:
im
=
im
.
resize
((
settings
.
crop_width
*
im
.
width
//
im
.
height
,
settings
.
crop_height
))
else
:
im
=
im
.
resize
((
settings
.
crop_width
,
settings
.
crop_height
))
if
im
.
height
==
im
.
width
:
scale_by
=
1
if
is_landscape
(
im
.
width
,
im
.
height
):
scale_by
=
settings
.
crop_height
/
im
.
height
elif
is_portrait
(
im
.
width
,
im
.
height
):
scale_by
=
settings
.
crop_width
/
im
.
width
elif
is_square
(
im
.
width
,
im
.
height
):
if
is_square
(
settings
.
crop_width
,
settings
.
crop_height
):
scale_by
=
settings
.
crop_width
/
im
.
width
elif
is_landscape
(
settings
.
crop_width
,
settings
.
crop_height
):
scale_by
=
settings
.
crop_width
/
im
.
width
elif
is_portrait
(
settings
.
crop_width
,
settings
.
crop_height
):
scale_by
=
settings
.
crop_height
/
im
.
height
im
=
im
.
resize
((
int
(
im
.
width
*
scale_by
),
int
(
im
.
height
*
scale_by
)))
if
im
.
width
==
settings
.
crop_width
and
im
.
height
==
settings
.
crop_height
:
if
settings
.
annotate_image
:
d
=
ImageDraw
.
Draw
(
im
)
rect
=
[
0
,
0
,
im
.
width
,
im
.
height
]
rect
[
2
]
-=
1
rect
[
3
]
-=
1
d
.
rectangle
(
rect
,
outline
=
GREEN
)
if
settings
.
destop_view_image
:
im
.
show
()
return
im
return
im
focus
=
focal_point
(
im
,
settings
)
focus
=
focal_point
(
im
,
settings
)
...
@@ -214,6 +231,18 @@ def poi_average(pois, settings):
...
@@ -214,6 +231,18 @@ def poi_average(pois, settings):
return
PointOfInterest
(
avg_x
,
avg_y
)
return
PointOfInterest
(
avg_x
,
avg_y
)
def
is_landscape
(
w
,
h
):
return
w
>
h
def
is_portrait
(
w
,
h
):
return
h
>
w
def
is_square
(
w
,
h
):
return
w
==
h
class
PointOfInterest
:
class
PointOfInterest
:
def
__init__
(
self
,
x
,
y
,
weight
=
1.0
,
size
=
10
):
def
__init__
(
self
,
x
,
y
,
weight
=
1.0
,
size
=
10
):
self
.
x
=
x
self
.
x
=
x
...
...
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