fix error of 'ImageColorGenerator is smaller than the canvas'

This commit is contained in:
chflame163
2024-01-15 11:52:22 +08:00
committed by GitHub
parent c43425edd5
commit e7654ba351
+10 -2
View File
@@ -177,8 +177,14 @@ class ComfyWordCloud:
random_state = None
mask = None
image_width = width
image_height = height
if not mask_image == None:
mask = np.array(img_whitebackground(tensor2pil(mask_image)))
p_mask = tensor2pil(mask_image)
mask = np.array(img_whitebackground(p_mask))
image_width = p_mask.width
image_height = p_mask.height
# set wordcloud parameters
wc = WordCloud(width=width, height=height, scale=scale, margin=margin,
@@ -195,7 +201,9 @@ class ComfyWordCloud:
# generate recolor
if not color_ref_image == None:
image_colors = ImageColorGenerator(np.array(tensor2pil(color_ref_image)))
p_color_ref_image = tensor2pil(color_ref_image)
p_color_ref_image = p_color_ref_image.resize((image_width, image_height))
image_colors = ImageColorGenerator(np.array(p_color_ref_image))
wc.recolor(color_func=image_colors)
return (pil2tensor(wc.to_image()),)