diff --git a/README.MD b/README.MD index f837952..cc02d20 100644 --- a/README.MD +++ b/README.MD @@ -70,6 +70,7 @@ When this error has occurred, please check the network environment. ## Update **If the dependency package error after updating, please reinstall the relevant dependency packages.
+* [ImageScaleRestoreV2](#ImageScaleRestoreV2), [ImageScaleByAspectRatioV2](#ImageScaleByAspectRatioV2), [ImageAutoCropV2](#ImageAutoCropV2) nodes add options for ```width``` and ```height```, which can specify width or height as fixed values. * Commit [PurgeVRAM](#PurgeVRAM) node, Clean up VRAM an RAM. * Commit [AutoAdjust](#AutoAdjust) node, it can automatically adjust image contrast and white balance. * Commit [RGBValue](#RGBValue) node to output the color value as a single decimal value of R, G, B. This idea is from [vxinhao](https://github.com/vxinhao/color2rgb), Thanks. @@ -573,8 +574,8 @@ The V2 upgraded version of ImageScaleRestore. Node options: ![image](image/image_scale_restore_v2_node.png) The following changes have been made based on ImageScaleRestore: -* scale_by: Allow scaling by specified size on long or short sides. -* scale_by_length: When scale_by is set to "longest", this will be used as the length of the long edge of the image; When set to "shortest", it serves as the length of the short edge. +* scale_by: Allow scaling by specified dimensions for longest, shortest, width, or height. +* scale_by_length: The value here is used as ```scale_by``` to specify the length of the edge. ### ImageMaskScaleAs Scale the image or mask to the size of the reference image (or reference mask). @@ -632,8 +633,8 @@ V2 Upgraded Version of ImageScaleByAspectRatio Node options: ![image](image/image_scale_by_aspect_ratio_v2_node.png) The following changes have been made based on ImageScaleByAspectRatio: -* scale_to_side: Allow scaling by specified size on long or short sides. -* scale_to_length: When scale_by_side is set to "longest", this will be used as the length of the long edge of the image; When set to "shortest", it serves as the length of the short edge. +* scale_by: Allow scaling by specified dimensions for longest, shortest, width, or height. +* scale_by_length: The value here is used as ```scale_by``` to specify the length of the edge. @@ -1020,7 +1021,8 @@ The V2 upgrad version of ```ImageAutoCrop```, it has made the following changes * Add optional input for mask. when there is a mask input, use that input directly to skip the built-in mask generation. * Add ```fill_background```. When set to False, the background will not be processed and any parts beyond the frame will not be included in the output range. * ```aspect_ratio``` adds the ```original``` option. -* ```scale_by_longest_side``` changed to support scaling by long or short edge, set in ```scale_to_side```. The side length is set in ```scale_to__length```. +* scale_by: Allow scaling by specified dimensions for longest, shortest, width, or height. +* scale_by_length: The value here is used as ```scale_by``` to specify the length of the edge. ### GetImageSize diff --git a/README_CN.MD b/README_CN.MD index db50576..cb3676a 100644 --- a/README_CN.MD +++ b/README_CN.MD @@ -70,6 +70,7 @@ git clone https://github.com/chflame163/ComfyUI_LayerStyle.git ## 更新说明 **如果本插件更新后出现依赖包错误,请重新安装相关依赖包。 +* [ImageScaleRestoreV2](#ImageScaleRestoreV2), [ImageScaleByAspectRatioV2](#ImageScaleByAspectRatioV2), [ImageAutoCropV2](#ImageAutoCropV2)节点增加```width```和```height```选项,可指定宽度或高度为固定值。 * 添加 [PurgeVRAM](#PurgeVRAM) 节点, 清理显存和内存。 * 添加 [AutoAdjust](#AutoAdjust) 节点, 自动调整图片对比度和白平衡。 * 添加 [RGBValue](#RGBValue) 节点, 将色值输出为单独的R, G, B三个10进制数值。这个想法来自[vxinhao](https://github.com/vxinhao/color2rgb),感谢。 @@ -567,8 +568,8 @@ ImageScaleRestore的V2升级版。 节点选项说明: ![image](image/image_scale_restore_v2_node.png) 在ImageScaleRestore基础上做了如下改变: -* scale_by: 允许按长边或短边指定尺寸缩放。 -* scale_by_length: scale_by被设置为"longest"时,此项将作为是图像长边的长度; 设置为"shortest"时,作为短边的长度。 +* scale_by: 允许按长边、短边、宽度或高度指定尺寸缩放。 +* scale_by_length: 这里的数值作为scale_by指定边的长度。 ### ImageMaskScaleAs @@ -622,8 +623,8 @@ ImageScaleByAspectRatio的V2升级版 节点选项说明: ![image](image/image_scale_by_aspect_ratio_v2_node.png) 在ImageScaleByAspectRatio基础上做了如下改变: -* scale_to_side: 允许按长边或短边指定尺寸缩放。 -* scale_to_length: scale_by_side被设置为"longest"时,此项将作为是图像长边的长度; 设置为"shortest"时,作为短边的长度。 +* scale_by: 允许按长边、短边、宽度或高度指定尺寸缩放。 +* scale_by_length: 这里的数值作为scale_by指定边的长度。 @@ -1009,7 +1010,8 @@ cropped_mask: 裁切后的遮罩。 * 增加```mask```可选输入。当有mask输入时,直接使用该输入跳过内置遮罩生成。 * 增加```fill_background```, 当此项设置为False时将不处理背景,并且超出画幅的部分不纳入输出范围。 * ```aspect_ratio```增加```original```(原始画面宽高比)选项。 -* 按长边缩放改为支持按长边或短边缩放,在```scale_to_side```中设置。边长在```scale_to_length```中设置。 +* scale_by: 允许按长边、短边、宽度或高度指定尺寸缩放。 +* scale_by_length: 这里的数值作为scale_by指定边的长度。 ### GetImageSize diff --git a/py/image_auto_crop_v2.py b/py/image_auto_crop_v2.py index 7aa7776..d6634fe 100644 --- a/py/image_auto_crop_v2.py +++ b/py/image_auto_crop_v2.py @@ -18,7 +18,7 @@ def INPUT_TYPES(self): matting_method_list = ['RMBG 1.4', 'SegmentAnything'] detect_mode = ['min_bounding_rect', 'max_inscribed_rect', 'mask_area'] ratio_list = ['1:1', '3:2', '4:3', '16:9', '2:3', '3:4', '9:16', 'custom', 'detect_mask', 'original'] - scale_to_side_list = ['None', 'longest', 'shortest'] + scale_to_side_list = ['None', 'longest', 'shortest', 'width', 'height'] return { "required": { "image": ("IMAGE", ), # @@ -183,6 +183,12 @@ def image_auto_crop_v2(self, image, fill_background, background_color, aspect_ra elif scale_to_side == 'shortest': target_height = scale_to_length target_width = int(target_height * ratio) + elif scale_to_side == 'width': + target_width = scale_to_length + target_height = int(target_width / ratio) + elif scale_to_side == 'height': + target_height = scale_to_length + target_width = int(target_height * ratio) else: target_width = orig_width target_height = int(target_width / ratio) @@ -193,6 +199,12 @@ def image_auto_crop_v2(self, image, fill_background, background_color, aspect_ra elif scale_to_side == 'shortest': target_width = scale_to_length target_height = int(target_width / ratio) + elif scale_to_side == 'width': + target_width = scale_to_length + target_height = int(target_width / ratio) + elif scale_to_side == 'height': + target_height = scale_to_length + target_width = int(target_height * ratio) else: target_height = orig_height target_width = int(target_height * ratio) diff --git a/py/image_scale_by_aspect_ratio_v2.py b/py/image_scale_by_aspect_ratio_v2.py index 90b233b..86f414f 100644 --- a/py/image_scale_by_aspect_ratio_v2.py +++ b/py/image_scale_by_aspect_ratio_v2.py @@ -15,7 +15,7 @@ def INPUT_TYPES(self): fit_mode = ['letterbox', 'crop', 'fill'] method_mode = ['lanczos', 'bicubic', 'hamming', 'bilinear', 'box', 'nearest'] multiple_list = ['8', '16', '32', '64', 'None'] - scale_to_list = ['None', 'longest', 'shortest'] + scale_to_list = ['None', 'longest', 'shortest', 'width', 'height'] return { "required": { "aspect_ratio": (ratio_list,), @@ -90,6 +90,12 @@ def image_scale_by_aspect_ratio(self, aspect_ratio, proportional_width, proporti elif scale_to_side == 'shortest': target_height = scale_to_length target_width = int(target_height * ratio) + elif scale_to_side == 'width': + target_width = scale_to_length + target_height = int(target_width / ratio) + elif scale_to_side == 'height': + target_height = scale_to_length + target_width = int(target_height * ratio) else: target_width = orig_width target_height = int(target_width / ratio) @@ -100,6 +106,12 @@ def image_scale_by_aspect_ratio(self, aspect_ratio, proportional_width, proporti elif scale_to_side == 'shortest': target_width = scale_to_length target_height = int(target_width / ratio) + elif scale_to_side == 'width': + target_width = scale_to_length + target_height = int(target_width / ratio) + elif scale_to_side == 'height': + target_height = scale_to_length + target_width = int(target_height * ratio) else: target_height = orig_height target_width = int(target_height * ratio) diff --git a/py/image_scale_restore_v2.py b/py/image_scale_restore_v2.py index ed91118..05bab3c 100644 --- a/py/image_scale_restore_v2.py +++ b/py/image_scale_restore_v2.py @@ -10,7 +10,7 @@ def __init__(self): @classmethod def INPUT_TYPES(self): method_mode = ['lanczos', 'bicubic', 'hamming', 'bilinear', 'box', 'nearest'] - scale_by_list = ['by_scale', 'longest', 'shortest'] + scale_by_list = ['by_scale', 'longest', 'shortest', 'width', 'height'] return { "required": { "image": ("IMAGE", ), # @@ -75,6 +75,12 @@ def image_scale_restore(self, image, scale, method, else: target_height = scale_by_length target_width = int(target_height * orig_width / orig_height) + if scale_by == 'width': + target_width = scale_by_length + target_height = int(target_width * orig_height / orig_width) + if scale_by == 'height': + target_height = scale_by_length + target_width = int(target_height * orig_width / orig_height) if target_width < 4: target_width = 4 if target_height < 4: