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
6e1b296b
Unverified
Commit
6e1b296b
authored
Jan 23, 2023
by
Vladimir Mandic
Committed by
GitHub
Jan 23, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api-image-format
parent
e8c3d03f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
10 deletions
+24
-10
api.py
modules/api/api.py
+24
-10
No files found.
modules/api/api.py
View file @
6e1b296b
...
@@ -22,6 +22,8 @@ from modules.sd_models import checkpoints_list, find_checkpoint_config
...
@@ -22,6 +22,8 @@ from modules.sd_models import checkpoints_list, find_checkpoint_config
from
modules.realesrgan_model
import
get_realesrgan_models
from
modules.realesrgan_model
import
get_realesrgan_models
from
modules
import
devices
from
modules
import
devices
from
typing
import
List
from
typing
import
List
import
piexif
import
piexif.helper
def
upscaler_to_index
(
name
:
str
):
def
upscaler_to_index
(
name
:
str
):
try
:
try
:
...
@@ -56,18 +58,30 @@ def decode_base64_to_image(encoding):
...
@@ -56,18 +58,30 @@ def decode_base64_to_image(encoding):
def
encode_pil_to_base64
(
image
):
def
encode_pil_to_base64
(
image
):
with
io
.
BytesIO
()
as
output_bytes
:
with
io
.
BytesIO
()
as
output_bytes
:
# Copy any text-only metadata
if
opts
.
samples_format
.
lower
()
==
'png'
:
use_metadata
=
False
use_metadata
=
False
metadata
=
PngImagePlugin
.
PngInfo
()
metadata
=
PngImagePlugin
.
PngInfo
()
for
key
,
value
in
image
.
info
.
items
():
for
key
,
value
in
image
.
info
.
items
():
if
isinstance
(
key
,
str
)
and
isinstance
(
value
,
str
):
if
isinstance
(
key
,
str
)
and
isinstance
(
value
,
str
):
metadata
.
add_text
(
key
,
value
)
metadata
.
add_text
(
key
,
value
)
use_metadata
=
True
use_metadata
=
True
image
.
save
(
output_bytes
,
format
=
"PNG"
,
pnginfo
=
(
metadata
if
use_metadata
else
None
),
quality
=
opts
.
jpeg_quality
)
elif
opts
.
samples_format
.
lower
()
in
(
"jpg"
,
"jpeg"
,
"webp"
):
parameters
=
image
.
info
.
get
(
'parameters'
,
None
)
exif_bytes
=
piexif
.
dump
({
"Exif"
:
{
piexif
.
ExifIFD
.
UserComment
:
piexif
.
helper
.
UserComment
.
dump
(
parameters
or
""
,
encoding
=
"unicode"
)
}
})
if
opts
.
samples_format
.
lower
()
in
(
"jpg"
,
"jpeg"
):
image
.
save
(
output_bytes
,
format
=
"JPEG"
,
exif
=
exif_bytes
,
quality
=
opts
.
jpeg_quality
)
else
:
image
.
save
(
output_bytes
,
format
=
"WEBP"
,
exif
=
exif_bytes
,
quality
=
opts
.
jpeg_quality
)
else
:
raise
HTTPException
(
status_code
=
500
,
detail
=
"Invalid image format"
)
image
.
save
(
output_bytes
,
"PNG"
,
pnginfo
=
(
metadata
if
use_metadata
else
None
)
)
bytes_data
=
output_bytes
.
getvalue
()
bytes_data
=
output_bytes
.
getvalue
()
return
base64
.
b64encode
(
bytes_data
)
return
base64
.
b64encode
(
bytes_data
)
def
api_middleware
(
app
:
FastAPI
):
def
api_middleware
(
app
:
FastAPI
):
...
...
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