Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Commit

Permalink
'update'
Browse files Browse the repository at this point in the history
  • Loading branch information
wailovet committed May 9, 2024
1 parent ad59f39 commit 3d6db91
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# ComfyUI-StylizePhoto
# ComfyUI-StylizePhoto-MZ
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def INPUT_TYPES(s):
"denoise": ("FLOAT", {"default": 0.75, "min": 0.0, "max": 1.0, "step": 0.01}),
"positive_prompt": ("STRING", {"default": ""}),
"negative_prompt": ("STRING", {"default": ""}),
"watermark": ("STRING", {"default": "ComfyUI\nGenerated by AI", "multiline": True}),
},
"optional":{
"model": ("MODEL",),
Expand Down
9 changes: 9 additions & 0 deletions mz_stylize_photo_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,15 @@ def ksampler(kwargs):
latent = common_ksampler(model, seed, steps, cfg, sampler_name, scheduler, positive, negative, latent_image, denoise=denoise)[0]

image = VAEDecode().decode(vae, latent)[0]


watermark = kwargs.get("watermark", "")
if watermark != "":
image = Utils.tensor2pil(image)
image = Utils.add_watermark(image, watermark)
image = Utils.pil2tensor(image)
image = Utils.list_tensor2tensor([image])

return (image,)


Expand Down
44 changes: 44 additions & 0 deletions mz_stylize_photo_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,50 @@ def resize_max(im, dst_w, dst_h):

return im.resize((newWidth, newHeight), Image.Resampling.LANCZOS)

def add_watermark(image, watermark):
if watermark == "":
return image
from PIL import ImageDraw, ImageFont

font_fullpath = Utils.download_model(
{
"url": "https://www.modelscope.cn/api/v1/models/wailovet/MinusZoneAIModels/repo?Revision=master&FilePath=font%2FAlibabaPuHuiTi-2-75-SemiBold.ttf",
"output": "font/AlibabaPuHuiTi-2-75-SemiBold.ttf",
}
)

watermarks = watermark.split("\n")

width, height = image.size
short_edge = min(width, height)
font_size = short_edge // 12


font = ImageFont.truetype(font_fullpath, font_size)
draw = ImageDraw.Draw(image)

text = watermarks[0]
textwidth, textheight = draw.textsize(text, font)

x = (width - textwidth) // 2

bottom = 10

y = height - textheight - (textheight * 0.4 + bottom + 8)
draw.text((x, y), text, font=font)

if len(watermarks) > 1:
y1 = y + textheight
text = watermarks[1]
font_size = int(font_size * 0.4)
font = ImageFont.truetype(font_fullpath, font_size)
textwidth, textheight = draw.textsize(text, font)
x = (width - textwidth) // 2
y = y1 - bottom + 4
draw.text((x, y), text, font=font)

return image

def get_device():
return comfy.model_management.get_torch_device()

Expand Down

0 comments on commit 3d6db91

Please sign in to comment.