fix(captcha2): 修复验证码字符垂直定位错误导致显示不全

generate_image() 中 y_dist(2,12) 在 Python 原版是顶部留白语义,
C++ 重写时误用为字符中心 y 坐标(cy = y - rh/2),
旋转后位图高度 rh 约 25~46px,cy 为负值导致字符上半部被裁掉。

修复:恢复 y 为顶部留白语义(cy = y),加边界钳制确保字符完整
落在 160×50 画布内。同步修复 test_gen.cpp 中的同款代码。
This commit is contained in:
qing committed 2026-08-09 04:58:41 +00:00
1 parent 6cf535eb79
commit 6bd0fcaf9b
2 files changed
+9 -3

No files matched your search

+5 -2
View File
@@ -451,9 +451,12 @@ static std::vector<uint8_t> generate_image(const std::string& text, const std::s
int rw, rh;
auto rotated = rotate_bitmap(bmp, angle, rw, rh);
// 合成位置:目标中心对准期望位置
// 合成位置:水平居中于 x,y 为顶部留白(与 Python 版语义一致)
// 底部越界时上移钳制,保证字符完整落在画布内
int cx = x - rw / 2;
int cy = y - rh / 2;
int cy = y;
if (cy + rh > kImgHeight) cy = kImgHeight - rh;
if (cy < 0) cy = 0;
composite_char(pixels, rotated, rw, rh, cx, cy, fg);
}