Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Overbill1683
Stable Diffusion Webui
提交
6e1b296b
S
Stable Diffusion Webui
项目概览
Overbill1683
/
Stable Diffusion Webui
10 个月 前同步成功
通知
1746
Star
81
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
分析
仓库
DevOps
项目成员
Pages
S
Stable Diffusion Webui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Pages
分析
分析
仓库分析
DevOps
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
提交
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
6e1b296b
编写于
1月 23, 2023
作者:
V
Vladimir Mandic
提交者:
GitHub
1月 23, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
api-image-format
上级
e8c3d03f
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
24 addition
and
10 deletion
+24
-10
modules/api/api.py
modules/api/api.py
+24
-10
未找到文件。
modules/api/api.py
浏览文件 @
6e1b296b
...
...
@@ -22,6 +22,8 @@ from modules.sd_models import checkpoints_list, find_checkpoint_config
from
modules.realesrgan_model
import
get_realesrgan_models
from
modules
import
devices
from
typing
import
List
import
piexif
import
piexif.helper
def
upscaler_to_index
(
name
:
str
):
try
:
...
...
@@ -56,18 +58,30 @@ def decode_base64_to_image(encoding):
def
encode_pil_to_base64
(
image
):
with
io
.
BytesIO
()
as
output_bytes
:
# Copy any text-only metadata
use_metadata
=
False
metadata
=
PngImagePlugin
.
PngInfo
()
for
key
,
value
in
image
.
info
.
items
():
if
isinstance
(
key
,
str
)
and
isinstance
(
value
,
str
):
metadata
.
add_text
(
key
,
value
)
use_metadata
=
True
if
opts
.
samples_format
.
lower
()
==
'png'
:
use_metadata
=
False
metadata
=
PngImagePlugin
.
PngInfo
()
for
key
,
value
in
image
.
info
.
items
():
if
isinstance
(
key
,
str
)
and
isinstance
(
value
,
str
):
metadata
.
add_text
(
key
,
value
)
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
()
return
base64
.
b64encode
(
bytes_data
)
def
api_middleware
(
app
:
FastAPI
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录