Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vibe): Enhance add_image_to_black_background Function to Support 32-bit Transparency #34

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added playground/static_refer_banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions playground/vibe.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

async def generate(
prompt="1girl, year 2023, dynamic angle, best quality, amazing quality, very aesthetic, absurdres",
image_path="static_refer.png"
image_path="static_refer_banner.png"
):
jwt = os.getenv("NOVELAI_JWT", None)
if jwt is None:
Expand All @@ -36,7 +36,7 @@ async def generate(
action=Action.GENERATE,
sampler=Sampler.K_DPMPP_SDE,
reference_image=image,
reference_strength=0.6,
reference_strength=0.9,
reference_information_extracted=1,
add_original_image=True, # This Not affect the vibe generation
qualityToggle=True,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "novelai-python"
version = "0.3.7"
version = "0.3.8"
description = "Novelai Python Binding With Pydantic"
authors = [
{ name = "sudoskys", email = "[email protected]" },
Expand Down
8 changes: 4 additions & 4 deletions src/novelai_python/sdk/ai/generate_image/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def resize_image(image: Union[str, bytes], width: int, height: int):
@staticmethod
def add_image_to_black_background(image: Union[str, bytes], width: int = 448, height: int = 448):
"""
将图像缩放到一个指定的黑背景上,使其最大,比例不变
缩放图像到指定的黑色透明背景上,使其尽可能大且保持比例
:param image: 图像
:param width: 宽
:param height: 高
Expand All @@ -157,7 +157,7 @@ def add_image_to_black_background(image: Union[str, bytes], width: int = 448, he
if isinstance(image, str):
image = base64.b64decode(image)

open_image = Image.open(BytesIO(image))
open_image = Image.open(BytesIO(image)).convert("RGBA")
# 如果尺寸相同,直接返回
if open_image.width == width and open_image.height == height:
return base64.b64encode(image).decode("utf-8")
Expand All @@ -170,8 +170,8 @@ def add_image_to_black_background(image: Union[str, bytes], width: int = 448, he
new_image_size = (int(open_image.width * ratio), int(open_image.height * ratio))
open_image = open_image.resize(new_image_size, Image.Resampling.BICUBIC)

# 创建一个黑色背景的新图像
new_image = Image.new("RGB", (width, height), (0, 0, 0))
# 创建一个黑色透明背景的新图像,颜色深度32位
new_image = Image.new("RGBA", (width, height), (0, 0, 0, 0))

# 计算居中位置
position = ((width - open_image.width) // 2, (height - open_image.height) // 2)
Expand Down
Loading