diff --git a/README.MD b/README.MD index acf37a6..629b893 100644 --- a/README.MD +++ b/README.MD @@ -80,7 +80,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) node add the ```total_pixel``` method to scale images. +* [ImageScaleRestoreV2](#ImageScaleRestoreV2) and [ImageScaleByAspectRatioV2](#ImageScaleByAspectRatioV2) nodes add the ```total_pixel``` method to scale images. * Commit [MediapipeFacialSegment](#MediapipeFacialSegment) node,Used to segment facial features, including left and right eyebrows, eyes, lips, and teeth. * Commit [BatchSelector](#BatchSelector) node,Used to retrieve specified images or masks from batch images or masks. * LayerUtility creates new subdirectories such as SystemIO, Data, and Prompt. Some nodes are classified into subdirectories. @@ -653,8 +653,8 @@ V2 Upgraded Version of ImageScaleByAspectRatio Node options: ![image](image/image_scale_by_aspect_ratio_v2_node.jpg) The following changes have been made based on ImageScaleByAspectRatio: -* 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. +* scale_to_side: Allow scaling by specified dimensions for long, short, width, height, or total pixels. +* scale_to_length: The numerical value here serves as the length of the specified edge or the total pixels (kilo pixels) for scale_to_side. diff --git a/README_CN.MD b/README_CN.MD index 63f0d8b..74f08d6 100644 --- a/README_CN.MD +++ b/README_CN.MD @@ -80,7 +80,7 @@ git clone https://github.com/chflame163/ComfyUI_LayerStyle.git ## 更新说明 **如果本插件更新后出现依赖包错误,请重新安装相关依赖包。 -* [ImageScaleRestoreV2](#ImageScaleRestoreV2)节点增加TotalPixel方法缩放图片。 +* [ImageScaleRestoreV2](#ImageScaleRestoreV2) 和[ImageScaleByAspectRatioV2](#ImageScaleByAspectRatioV2) 节点增加TotalPixel方法缩放图片。 * 添加 [MediapipeFacialSegment](#MediapipeFacialSegment) 节点, 用于分割面部五官,包括左右眉、眼睛、嘴唇和牙齿。 * 添加 [BatchSelector](#BatchSelector) 节点, 用于从批量图片或遮罩中获取指定的图片或遮罩。 * LayerUtility大类新建子目录SystemIO, Data, Prompt。一部分节点被分类到子目录。 @@ -643,8 +643,8 @@ ImageScaleByAspectRatio的V2升级版 节点选项说明: ![image](image/image_scale_by_aspect_ratio_v2_node.jpg) 在ImageScaleByAspectRatio基础上做了如下改变: -* scale_by: 允许按长边、短边、宽度或高度指定尺寸缩放。 -* scale_by_length: 这里的数值作为scale_by指定边的长度。 +* scale_to_side: 允许按长边、短边、宽度、高度或总像素指定尺寸缩放。 +* scale_to_length: 这里的数值作为scale_to_side指定边的长度, 或者总像素数量(kilo pixels)。 diff --git a/py/image_scale_by_aspect_ratio_v2.py b/py/image_scale_by_aspect_ratio_v2.py index c099a4d..33cd225 100644 --- a/py/image_scale_by_aspect_ratio_v2.py +++ b/py/image_scale_by_aspect_ratio_v2.py @@ -15,7 +15,7 @@ class ImageScaleByAspectRatioV2: 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', 'width', 'height'] + scale_to_list = ['None', 'longest', 'shortest', 'width', 'height', 'total_pixel(kilo pixel)'] return { "required": { "aspect_ratio": (ratio_list,), @@ -96,6 +96,11 @@ class ImageScaleByAspectRatioV2: elif scale_to_side == 'height': target_height = scale_to_length target_width = int(target_height * ratio) + elif scale_to_side == 'total_pixel(kilo pixel)': + target_width = math.sqrt(ratio * scale_to_length * 1000) + target_height = target_width / ratio + target_width = int(target_width) + target_height = int(target_height) else: target_width = orig_width target_height = int(target_width / ratio) @@ -112,6 +117,11 @@ class ImageScaleByAspectRatioV2: elif scale_to_side == 'height': target_height = scale_to_length target_width = int(target_height * ratio) + elif scale_to_side == 'total_pixel(kilo pixel)': + target_width = math.sqrt(ratio * scale_to_length * 1000) + target_height = target_width / ratio + target_width = int(target_width) + target_height = int(target_height) else: target_height = orig_height target_width = int(target_height * ratio)