Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
chflame163 committed Dec 10, 2024
1 parent 04fa5d6 commit a3d00bf
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
4 changes: 2 additions & 2 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ Some JSON workflow files in the ```workflow``` directory, That's examples of
git clone https://github.com/chflame163/ComfyUI_LayerStyle.git
```

* Or download the zip file and extracted, copy the resulting folder to ```ComfyUI\custom_ Nodes```
* Or download the zip file and extracted, copy the resulting folder to ```ComfyUI\custom_nodes```

### Install dependency packages

* for ComfyUI official portable package, double-click the ```install_requirements.bat``` in the plugin directory, for Aki ComfyUI package double-click on the ```install_requirements_aki.bat``` in the plugin directory, and wait for the installation to complete.

* Or install dependency packages, open the cmd window in the ComfyUI_LayerStyle plugin directory like
```ComfyUI\custom_ Nodes\ComfyUI_LayerStyle``` and enter the following command,
```ComfyUI\custom_nodes\ComfyUI_LayerStyle``` and enter the following command,

  for ComfyUI official portable package, type:

Expand Down
104 changes: 52 additions & 52 deletions py/imagefunc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1253,58 +1253,6 @@ def pixel_spread(image:Image, mask:Image) -> Image:
return tensor2pil(torch.from_numpy(fg.astype(np.float32)))


def generate_text_image(text:str, font_path:str, font_size:int, text_color:str="#FFFFFF",
vertical:bool=True, stroke_width:int=1, stroke_color:str="#000000",
spacing:int=0, leading:int=0) -> tuple:

lines = text.split("\n")
if vertical:
layout = "vertical"
else:
layout = "horizontal"
char_coordinates = []
if layout == "vertical":
x = 0
y = 0
for i in range(len(lines)):
line = lines[i]
for char in line:
char_coordinates.append((x, y))
y += font_size + spacing
x += font_size + leading
y = 0
else:
x = 0
y = 0
for line in lines:
for char in line:
char_coordinates.append((x, y))
x += font_size + spacing
y += font_size + leading
x = 0
if layout == "vertical":
width = (len(lines) * (font_size + spacing)) - spacing
height = ((len(max(lines, key=len)) + 1) * (font_size + spacing)) + spacing
else:
width = (len(max(lines, key=len)) * (font_size + spacing)) - spacing
height = ((len(lines) - 1) * (font_size + spacing)) + font_size

image = Image.new('RGBA', size=(width, height), color=stroke_color)
draw = ImageDraw.Draw(image)
font = ImageFont.truetype(font_path, font_size)
index = 0
for i, line in enumerate(lines):
for j, char in enumerate(line):
x, y = char_coordinates[index]
if stroke_width > 0:
draw.text((x - stroke_width, y), char, font=font, fill=stroke_color)
draw.text((x + stroke_width, y), char, font=font, fill=stroke_color)
draw.text((x, y - stroke_width), char, font=font, fill=stroke_color)
draw.text((x, y + stroke_width), char, font=font, fill=stroke_color)
draw.text((x, y), char, font=font, fill=text_color)
index += 1
return (image.convert('RGB'), image.split()[3])

def watermark_image_size(image:Image) -> int:
size = int(math.sqrt(image.width * image.height * 0.015625) * 0.9)
return size
Expand Down Expand Up @@ -1393,6 +1341,58 @@ def decode_watermark(image:Image, watermark_image_size:int=94) -> Image:
ret_image = normalize_gray(ret_image)
return ret_image

# def generate_text_image(text:str, font_path:str, font_size:int, text_color:str="#FFFFFF",
# vertical:bool=True, stroke_width:int=1, stroke_color:str="#000000",
# spacing:int=0, leading:int=0) -> tuple:
#
# lines = text.split("\n")
# if vertical:
# layout = "vertical"
# else:
# layout = "horizontal"
# char_coordinates = []
# if layout == "vertical":
# x = 0
# y = 0
# for i in range(len(lines)):
# line = lines[i]
# for char in line:
# char_coordinates.append((x, y))
# y += font_size + spacing
# x += font_size + leading
# y = 0
# else:
# x = 0
# y = 0
# for line in lines:
# for char in line:
# char_coordinates.append((x, y))
# x += font_size + spacing
# y += font_size + leading
# x = 0
# if layout == "vertical":
# width = (len(lines) * (font_size + spacing)) - spacing
# height = ((len(max(lines, key=len)) + 1) * (font_size + spacing)) + spacing
# else:
# width = (len(max(lines, key=len)) * (font_size + spacing)) - spacing
# height = ((len(lines) - 1) * (font_size + spacing)) + font_size
#
# image = Image.new('RGBA', size=(width, height), color=stroke_color)
# draw = ImageDraw.Draw(image)
# font = ImageFont.truetype(font_path, font_size)
# index = 0
# for i, line in enumerate(lines):
# for j, char in enumerate(line):
# x, y = char_coordinates[index]
# if stroke_width > 0:
# draw.text((x - stroke_width, y), char, font=font, fill=stroke_color)
# draw.text((x + stroke_width, y), char, font=font, fill=stroke_color)
# draw.text((x, y - stroke_width), char, font=font, fill=stroke_color)
# draw.text((x, y + stroke_width), char, font=font, fill=stroke_color)
# draw.text((x, y), char, font=font, fill=text_color)
# index += 1
# return (image.convert('RGB'), image.split()[3])

def generate_text_image(width:int, height:int, text:str, font_file:str, text_scale:float=1, font_color:str="#FFFFFF",) -> Image:
image = Image.new("RGBA", (width, height), (0, 0, 0, 0))
draw = ImageDraw.Draw(image)
Expand Down

0 comments on commit a3d00bf

Please sign in to comment.