fix: correct fx resize behavior #57

Merged
Passthem merged 1 commits from pi-agent/konabot:fix/fx-resize-behavior into master 2026-03-14 01:11:45 +08:00
Contributor

PR Type

Bug fix, Tests


Description

  • 修复缩放边界逻辑

  • 确保最小尺寸一像素

  • 重构函数提高可读性

  • 新增缩放边界测试


Diagram Walkthrough

flowchart LR
  Start["输入图像"]
  Check["检查缩放比例"]
  Transform["翻转或镜像"]
  Calc["计算新尺寸"]
  Clamp["限制最小尺寸"]
  End["输出图像"]
  Start --> Check
  Check --> Transform
  Transform --> Calc
  Calc --> Clamp
  Clamp --> End

File Walkthrough

Relevant files
Bug fix
fx_handle.py
重构缩放逻辑并修复边界                                                                                           

konabot/plugins/fx_process/fx_handle.py

  • 重构 apply_resize 函数逻辑
  • 修复负数缩放导致的翻转错误
  • 限制最小缩放尺寸为一像素
+19/-15 
Tests
test_fx_process.py
增加缩放功能单元测试                                                                                             

tests/test_fx_process.py

  • 新增缩放尺寸下限测试
  • 新增负数缩放行为测试
+36/-0   

### **PR Type** Bug fix, Tests ___ ### **Description** - 修复缩放边界逻辑 - 确保最小尺寸一像素 - 重构函数提高可读性 - 新增缩放边界测试 ___ ### Diagram Walkthrough ```mermaid flowchart LR Start["输入图像"] Check["检查缩放比例"] Transform["翻转或镜像"] Calc["计算新尺寸"] Clamp["限制最小尺寸"] End["输出图像"] Start --> Check Check --> Transform Transform --> Calc Calc --> Clamp Clamp --> End ``` <details> <summary><h3> File Walkthrough</h3></summary> <table><thead><tr><th></th><th align="left">Relevant files</th></tr></thead><tbody><tr><td><strong>Bug fix</strong></td><td><table> <tr> <td> <details> <summary><strong>fx_handle.py</strong><dd><code>重构缩放逻辑并修复边界</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> konabot/plugins/fx_process/fx_handle.py - 重构 `apply_resize` 函数逻辑 - 修复负数缩放导致的翻转错误 - 限制最小缩放尺寸为一像素 </details> </td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/fix/fx-resize-behavior/konabot/plugins/fx_process/fx_handle.py">+19/-15</a>&nbsp; </td> </tr> </table></td></tr><tr><td><strong>Tests</strong></td><td><table> <tr> <td> <details> <summary><strong>test_fx_process.py</strong><dd><code>增加缩放功能单元测试</code>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </dd></summary> <hr> tests/test_fx_process.py - 新增缩放尺寸下限测试 - 新增负数缩放行为测试 </details> </td> <td><a href="https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/fix/fx-resize-behavior/tests/test_fx_process.py">+36/-0</a>&nbsp; &nbsp; </td> </tr> </table></td></tr></tr></tbody></table> </details> ___
pi-agent added 1 commit 2026-03-14 01:07:44 +08:00
Passthem requested review from Passthem 2026-03-14 01:08:21 +08:00
Collaborator

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 2 🔵🔵
🧪 PR contains tests
🔒 No security concerns identified
 Recommended focus areas for review

代码一致性

函数 apply_resize 的参数 scale_y 缺少类型提示,而 scale 参数有。建议添加 float | None 类型注解以保持代码风格一致并增强类型安全性。

def apply_resize(image: Image.Image, scale: float = 1.5, scale_y = None) -> Image.Image:
## PR Reviewer Guide 🔍 Here are some key observations to aid the review process: <table> <tr><td>⏱️&nbsp;<strong>Estimated effort to review</strong>: 2 🔵🔵⚪⚪⚪</td></tr> <tr><td>🧪&nbsp;<strong>PR contains tests</strong></td></tr> <tr><td>🔒&nbsp;<strong>No security concerns identified</strong></td></tr> <tr><td>⚡&nbsp;<strong>Recommended focus areas for review</strong><br><br> <details><summary><a href='https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/fix/fx-resize-behavior/konabot/plugins/fx_process/fx_handle.py#L196-L196'><strong>代码一致性</strong></a> 函数 `apply_resize` 的参数 `scale_y` 缺少类型提示,而 `scale` 参数有。建议添加 `float | None` 类型注解以保持代码风格一致并增强类型安全性。 </summary> ```python def apply_resize(image: Image.Image, scale: float = 1.5, scale_y = None) -> Image.Image: ``` </details> </td></tr> </table>
Passthem approved these changes 2026-03-14 01:11:23 +08:00
Passthem merged commit 1a2a3c0468 into master 2026-03-14 01:11:45 +08:00
Collaborator

PR Code Suggestions

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
General
重命名变量以提高清晰度

变量命名 scale_y_value 与参数 scale_y 过于相似,容易造成混淆。建议重命名为 abs_scale_y 以明确其存储的是绝对值,提高代码可读性。

konabot/plugins/fx_process/fx_handle.py [197-207]

 scale_x = float(scale)
-scale_y_value = float(scale_y) if scale_y is not None else None
+abs_scale_y = float(scale_y) if scale_y is not None else None
 
-if scale_y_value is not None:
-    if scale_y_value < 0:
+if abs_scale_y is not None:
+    if abs_scale_y < 0:
         image = ImageOps.flip(image)
-        scale_y_value = abs(scale_y_value)
+        abs_scale_y = abs(abs_scale_y)
     if scale_x < 0:
         image = ImageOps.mirror(image)
         scale_x = abs(scale_x)
-    target_scale_y = scale_y_value
+    target_scale_y = abs_scale_y
Suggestion importance[1-10]: 2

__

Why: 变量重命名属于低影响的重构建议。且提议的名称 abs_scale_y 具有误导性,因为该变量在初始化时可能为负值,仅在后续逻辑中转为绝对值,降低了代码语义的准确性。

Low
## PR Code Suggestions ✨ <!-- f7cea19 --> Explore these optional code suggestions: <table><thead><tr><td><strong>Category</strong></td><td align=left><strong>Suggestion&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </strong></td><td align=center><strong>Impact</strong></td></tr><tbody><tr><td rowspan=1>General</td> <td> <details><summary>重命名变量以提高清晰度</summary> ___ **变量命名 <code>scale_y_value</code> 与参数 <code>scale_y</code> 过于相似,容易造成混淆。建议重命名为 <code>abs_scale_y</code> 以明确其存储的是绝对值,提高代码可读性。** [konabot/plugins/fx_process/fx_handle.py [197-207]](https://gitea.service.jazzwhom.top/mttu-developers/konabot/src/branch/fix/fx-resize-behavior/konabot/plugins/fx_process/fx_handle.py#L197-L207) ```diff scale_x = float(scale) -scale_y_value = float(scale_y) if scale_y is not None else None +abs_scale_y = float(scale_y) if scale_y is not None else None -if scale_y_value is not None: - if scale_y_value < 0: +if abs_scale_y is not None: + if abs_scale_y < 0: image = ImageOps.flip(image) - scale_y_value = abs(scale_y_value) + abs_scale_y = abs(abs_scale_y) if scale_x < 0: image = ImageOps.mirror(image) scale_x = abs(scale_x) - target_scale_y = scale_y_value + target_scale_y = abs_scale_y ``` <details><summary>Suggestion importance[1-10]: 2</summary> __ Why: 变量重命名属于低影响的重构建议。且提议的名称 `abs_scale_y` 具有误导性,因为该变量在初始化时可能为负值,仅在后续逻辑中转为绝对值,降低了代码语义的准确性。 </details></details></td><td align=center>Low </td></tr></tr></tbody></table>
Sign in to join this conversation.
No description provided.